Type error: The inferred type of 'api' cannot be named without a reference to '../../../../packages/db/node_modules/@prisma/client/runtime/library'

143 views Asked by At

I am creating a webapp (convoform.com), I have now setup turborepo in this repo which have a nextjs + prisma + trpc. It is working locally using "pnpm dev", but when i tried to build it using "pnpm build", I am getting below error.

web:build: Type error: The inferred type of 'api' cannot be named without a reference to '../../../../packages/db/node_modules/@prisma/client/runtime/library'. This is likely not portable. A type annotation is necessary.

Below is full log:

> turbo build

• Packages in scope: @convoform/api, @convoform/db, @convoform/eslint-config, @convoform/tsconfig, @convoform/ui, web
• Running build in 6 packages
• Remote caching disabled
@convoform/db:db:generate: cache bypass, force executing 724a3682c1a2d93d
@convoform/db:db:generate: 
@convoform/db:db:generate: > @convoform/[email protected] db:generate /Users/utkarshanand/Development/personal/smart-form-wizard/packages/db
@convoform/db:db:generate: > prisma generate
@convoform/db:db:generate: 
@convoform/db:db:generate: Prisma schema loaded from prisma/schema.prisma
@convoform/db:db:generate: 
@convoform/db:db:generate: ✔ Generated Prisma Client (v5.8.1) to ./../../node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client in 92ms
@convoform/db:db:generate: 
@convoform/db:db:generate: Start using Prisma Client in Node.js (See: https://pris.ly/d/client)
@convoform/db:db:generate: ```
@convoform/db:db:generate: import { PrismaClient } from '@prisma/client'
@convoform/db:db:generate: const prisma = new PrismaClient()
@convoform/db:db:generate: ```
@convoform/db:db:generate: or start using Prisma Client at the edge (See: https://pris.ly/d/accelerate)
@convoform/db:db:generate: ```
@convoform/db:db:generate: import { PrismaClient } from '@prisma/client/edge'
@convoform/db:db:generate: const prisma = new PrismaClient()
@convoform/db:db:generate: ```
@convoform/db:db:generate: 
@convoform/db:db:generate: See other ways of importing Prisma Client: http://pris.ly/d/importing-client
@convoform/db:db:generate: 
@convoform/db:db:generate: ┌─────────────────────────────────────────────────────────────┐
@convoform/db:db:generate: │  Deploying your app to serverless or edge functions?        │
@convoform/db:db:generate: │  Try Prisma Accelerate for connection pooling and caching.  │
@convoform/db:db:generate: │  https://pris.ly/cli/accelerate                             │
@convoform/db:db:generate: └─────────────────────────────────────────────────────────────┘
@convoform/db:db:generate: 
web:build: cache miss, executing 47d378c71dc23084
web:build: 
web:build: > [email protected] build /Users/utkarshanand/Development/personal/smart-form-wizard/apps/web
web:build: > next build
web:build: 
web:build:    ▲ Next.js 14.1.0
web:build:    - Environments: .env.local
web:build:    - Experiments (use at your own risk):
web:build:      · swcPlugins
web:build: 
web:build:    Creating an optimized production build ...
web:build:  ✓ Compiled successfully
web:build:    Linting and checking validity of types ...
web:build: Failed to compile.
web:build: 
web:build: ./src/trpc/server.ts:35:14
web:build: Type error: The inferred type of 'api' cannot be named without a reference to '../../../../packages/db/node_modules/@prisma/client/runtime/library'. This is likely not portable. A type annotation is necessary.
web:build: 
web:build:   33 | });
web:build:   34 |
web:build: > 35 | export const api = createTRPCProxyClient<AppRouter>({
web:build:      |              ^
web:build:   36 |   transformer: superjson,
web:build:   37 |   links: [
web:build:   38 |     loggerLink({
web:build:  ELIFECYCLE  Command failed with exit code 1.
web:build: ERROR: command finished with error: command (/Users/utkarshanand/Development/personal/smart-form-wizard/apps/web) /Users/utkarshanand/.volta/bin/pnpm run build exited (1)
web#build: command (/Users/utkarshanand/Development/personal/smart-form-wizard/apps/web) /Users/utkarshanand/.volta/bin/pnpm run build exited (1)

 Tasks:    1 successful, 2 total
Cached:    0 cached, 2 total
  Time:    40.395s 
Failed:    web#build

 ERROR  run failed: command  exited (1)
 ELIFECYCLE  Command failed with exit code 1.

I have tried all the config with tsconfig, I have tried many things nothing works.

One think i noticed if i don't use my prisma client in trpc package where i am creating context, this is error is gone.

https://github.com/growupanand/ConvoForm/blob/f6cf5ad33cdfa425076a2036b4e7d1075fe978ea/packages/api/server/api/trpc.ts#L33

2

There are 2 answers

0
GrowUpAnand On

It is fixed now,

I follow this guide, In short the solution is

Instead of using import { PrismaClient } from "@prisma/client";

We will use import { PrismaClient } from "../lib/generated/client";

This lib folder can be generated by adding the below line in your schema.prisma 's client section

output = "../lib/generated/client"

0
user23336000 On

Try to update complierOptions in your tsconfig:

"declarationMap": false,
"declaration": false,

Like my project PenX: https://github.com/penxio/penx/blob/59388fc01fe04f0f5fab9f8a45fe8af4e05dc4ae/packages/trpc-client/tsconfig.json#L4-L5