prisma icon indicating copy to clipboard operation
prisma copied to clipboard

[prisma-client generator]: Generated code can't be bundled by Next.js properly

Open CHC383 opened this issue 7 months ago • 1 comments

Bug description

The code generated by the prisma-client generator, specifically line 81 const require = createRequire(import.meta.url) in <output>/internal/class.ts, can't be bundled properly by Next.js (webpack), and the error message is

TypeError: t is not a function
    at Object.getQueryCompilerWasmModule (.next/server/app/page.js:1:29120)

This might be similar to https://github.com/vercel/next.js/issues/62953

Severity

⚠️ Major: Breaks core functionality (e.g., migrations fail)

Reproduction

https://codesandbox.io/p/github/CHC383/Next.js-Prisma-TS-Generator/main?import=true

  • pnpm i
  • pnpm build

Expected vs. Actual Behavior

Expected Generated client code can be bundled without issues

Actual Behavior Error as above

Frequency

Consistently reproducible

Does this occur in development or production?

Both development and production

Is this a regression?

Not sure, just started to play with the new prisma-client generator

Workaround

No workaround found

Prisma Schema & Queries

generator client {
  provider = "prisma-client"
  output   = "../src/generated/prisma"
  previewFeatures = ["queryCompiler", "driverAdapters", "strictUndefinedChecks"]
}

datasource db {
  provider  = "postgresql"
  url       = env("DATABASE_URL")
  directUrl = env("DATABASE_URL_UNPOOLED")
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
}
// N/A

Prisma Config

Logs & Debug Info

➜  workspace git:(main) ✗ pnpm build

> [email protected] build /project/workspace
> next build

   ▲ Next.js 15.3.3

   Creating an optimized production build ...
 ✓ Compiled successfully in 4.0s
 ✓ Linting and checking validity of types    
 ✓ Collecting page data    
TypeError: t is not a function
    at Object.getQueryCompilerWasmModule (.next/server/app/page.js:1:29120)
 ✓ Generating static pages (5/5)
TypeError: t is not a function
    at Object.getQueryCompilerWasmModule (.next/server/app/page.js:1:29120)
 ✓ Collecting build traces    
 ✓ Finalizing page optimization    

Environment & Setup

  • OS: Debian
  • Database: PostgreSQL
  • Node.js version: v20.12.0

Prisma Version

prisma                  : 6.9.0
@prisma/client          : 6.9.0
Computed binaryTarget   : debian-openssl-3.0.x
Operating System        : linux
Architecture            : x64
Node.js                 : v20.12.0
TypeScript              : unknown
Query Engine (Node-API) : libquery-engine 81e4af48011447c3cc503a190e86995b66d2a28e (at ../../root/.cache/pnpm/v3/tmp/dlx-11495/node_modules/.pnpm/@[email protected]/node_modules/@prisma/engines/libquery_engine-debian-openssl-3.0.x.so.node)
Schema Engine           : schema-engine-cli 81e4af48011447c3cc503a190e86995b66d2a28e (at ../../root/.cache/pnpm/v3/tmp/dlx-11495/node_modules/.pnpm/@[email protected]/node_modules/@prisma/engines/schema-engine-debian-openssl-3.0.x)
Schema Wasm             : @prisma/prisma-schema-wasm 6.9.0-10.81e4af48011447c3cc503a190e86995b66d2a28e
Default Engines Hash    : 81e4af48011447c3cc503a190e86995b66d2a28e
Studio                  : 0.511.0

CHC383 avatar Jun 06 '25 04:06 CHC383

The same issue I reported on other repos:

  • NextJs: https://github.com/vercel/next.js/issues/80257
  • Webpack: https://github.com/webpack/webpack/issues/19607

I think we either need a fix on Webpack, or update the Prisma generator to write the code in a bundler friendly way.

CHC383 avatar Jun 13 '25 23:06 CHC383

Thanks for creating issues on Webpack and NextJS side. It seems that the issue is on Webpack end based on this comment.

nurul3101 avatar Jun 18 '25 11:06 nurul3101

I can confirm that the bundle issue occurs with prisma-client generator. The issue gets fixed if we use prisma-client-js generator and remove the output path:

With prisma-client generator:

Image

With prisma-client-js generator and output path removed:

Image

nurul3101 avatar Jun 18 '25 12:06 nurul3101

Yes, Currently even I faced the same issue, removing the output = "../app/generated/prisma" fixes the problem. There is also another issue which shows up on using the output in app/generated that says TypeError: The "path" argument must be of type string. Received undefined. I removed it and used the default @prisma/client generator and it works properly

Morningstar-08 avatar Jun 18 '25 16:06 Morningstar-08