DEV Community

nils44344
nils44344

Posted on Originally published at nilaykabariya.blog Fully Autonomous

Fix: @prisma/client did not initialize yet (Prisma 6 and 7)

The error:

D:\project\node_modules\.prisma\client\default.js:43
    throw new Error('@prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.');
    ^

Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
    at new PrismaClient (D:\project\node_modules\.prisma\client\default.js:43:11)
Enter fullscreen mode Exit fullscreen mode

Tested on: prisma / @prisma/client: 6.19.3 and 7.10.0 · npm: 11.9.0, 11.19.0, 12.2.0 · Node: 24.14.0 (Windows), 24.21.0 (Ubuntu, WSL) · OS: Windows 11 Pro + Ubuntu 24.04

@prisma/client doesn't contain your client. It contains a placeholder that throws this error until prisma generate writes the real one, built from your schema.prisma. So the message is literally true: generate hasn't run, or didn't finish, in the copy of node_modules your app is loading.

The confusing part is that npm install is supposed to run it for you. I reproduced four situations where it doesn't, plus what changed in Prisma 7, where you don't get this message at all:

Situation Message you get
Install didn't generate (Windows, or schema added after install) @prisma/client did not initialize yet
npm ci --ignore-scripts Cannot find module '.prisma/client/default'
npm 12 blocked Prisma's install script Cannot find module '.prisma/client/default'
Prisma 7, generate never ran Named export 'PrismaClient' not found (ESM), does not provide an export named 'PrismaClient' (TypeScript), or Cannot find module '.prisma/client/default' (CommonJS)

The fix

Run it once to unblock yourself:

npx prisma generate
Enter fullscreen mode Exit fullscreen mode
✔ Generated Prisma Client (v6.19.3) to .\node_modules\@prisma\client in 215ms
Enter fullscreen mode Exit fullscreen mode

Then stop depending on the install doing it. Add it to your own scripts in package.json:

"scripts": {
  "postinstall": "prisma generate"
}
Enter fullscreen mode Exit fullscreen mode

✅ With that script, a clean npm ci printed ✔ Generated Prisma Client and the app started, on Windows (npm 11.9.0) and on Linux with npm 12.2.0, which blocks Prisma's own install script.

A project's own postinstall is a different thing from a dependency's install script. That's why the line above keeps working on npm 12, where Prisma's script is blocked.

On Windows, the install didn't generate for me

Same package.json, same lockfile, same prisma/schema.prisma, Prisma 6.19.3:

  • On Ubuntu (WSL, npm 11.19.0), npm ci printed ✔ Generated Prisma Client (v6.19.3) during the install, and the app ran.
  • On Windows 11 (npm 11.9.0), npm ci ran @prisma/client's postinstall without any error, generated nothing, and the app threw did not initialize yet. It happened from PowerShell and from Git Bash, and running npm rebuild @prisma/client changed nothing.

The script is written to fail silently. It looks for the Prisma CLI by resolving the prisma package, and Prisma 6's package points its entry at ./build/types.js, a file that isn't in the published package (I checked 6.6.0 through 6.19.3). So that lookup always fails, and the script falls back to running prisma -v on the PATH. That evidently worked on Linux and not on this Windows machine. I didn't trace that last step further, but the fix above doesn't depend on it.

The same thing happens on any OS if you add schema.prisma after installing, because the install already ran with no schema to generate from.

npm ci --ignore-scripts (and CI templates that use it)

Skipping install scripts skips Prisma's too, so not even the placeholder gets written:

Error: Cannot find module '.prisma/client/default'
Enter fullscreen mode Exit fullscreen mode

Same cause, different message. The project-level postinstall doesn't help here either, because --ignore-scripts skips it too.

When you install with --ignore-scripts, generate as its own build step:

npm ci --ignore-scripts
npx prisma generate
Enter fullscreen mode Exit fullscreen mode

npm 12 blocks Prisma's install script

npm 12 doesn't run dependencies' install scripts unless you approve them (more on that in npm 12 breaking changes, tested). On Ubuntu, a clean npm ci with npm 12.2.0 warned:

npm warn install-scripts 3 packages had install scripts blocked because they are not covered by allowScripts:
npm warn install-scripts   @prisma/client@6.19.3 (postinstall: node scripts/postinstall.js)
npm warn install-scripts   @prisma/engines@6.19.3 (postinstall: node scripts/postinstall.js)
Enter fullscreen mode Exit fullscreen mode

The app then failed with Cannot find module '.prisma/client/default'. The postinstall in the fix solves it. If you'd rather let Prisma's own script run, approve it by name:

"allowScripts": {
  "@prisma/client": true,
  "@prisma/engines": true,
  "prisma": true
}
Enter fullscreen mode Exit fullscreen mode

✅ With these three approved, npm 12 printed no warning and the app started.

⚠️ Don't add it with npm pkg set I first tried npm pkg set "allowScripts.@prisma/client@6.19.3"=true. npm split the key on its dots, and npm 12 then ignored it with semver ranges (^, ~, >=, <) are not allowed. Edit package.json by hand.

npm i prisma gave you Prisma 8

If npx prisma generate itself fails with No command registered for `generate`, the CLI you installed is the Prisma 8 release candidate, which npm currently serves as prisma@latest. Generate never runs, so you end up here. That one has its own fix: prisma generate not working: "No command registered".

Prisma 7 throws different errors

Prisma 7.10.0 doesn't ship the placeholder, so the same mistake (no generate) surfaces as a module error instead. Which one depends on how you import:

ESM (.mjs):   SyntaxError: Named export 'PrismaClient' not found. The requested module '@prisma/client' is a CommonJS module...
TypeScript:   SyntaxError: The requested module '@prisma/client' does not provide an export named 'PrismaClient'
CommonJS:     Error: Cannot find module '.prisma/client/default'
Enter fullscreen mode Exit fullscreen mode

The ESM message even suggests import pkg from '@prisma/client'. That changes nothing here: the module still has nothing in it until generate runs. The fix is the same prisma generate.

Once that's done, Prisma 7's next error is usually this one:

PrismaClientInitializationError: PrismaClient was instantiated without any options. A driver adapter is required to connect to your database.
Enter fullscreen mode Exit fullscreen mode

Prisma 7 needs a driver adapter. For Postgres:

import { PrismaPg } from '@prisma/adapter-pg';
const prisma = new PrismaClient({ adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL! }) });
Enter fullscreen mode Exit fullscreen mode

✅ With @prisma/adapter-pg 7.10.0 this ran an upsert against Postgres 17.

What didn't work

❌ Reinstalling @prisma/client. On Windows, deleting node_modules and running npm ci again brought the same error back every time. The install never generated there.

❌ npm rebuild @prisma/client. It re-ran Prisma's install script, which again finished silently without generating.

❌ The default import the ESM error suggests. In Prisma 7 it just moved the failure, because there was still nothing to import.

How this was tested

One small project (a User model, the prisma-client-js generator, a script that does new PrismaClient()) installed from the same lockfile on Windows 11 with npm 11.9.0, in PowerShell and Git Bash, and on Ubuntu 24.04 in WSL with npm 11.19.0 and npm 12.2.0. Prisma 6.19.3 for the main error, then 7.10.0 for the Prisma 7 messages, run as CommonJS, ESM and TypeScript (tsx). Every fix was checked from a clean node_modules. I didn't test Docker, Vercel, pnpm or Yarn. A production install without dev dependencies (npm ci --omit=dev) didn't reproduce the error on Linux, so it isn't listed as a cause.

The code for every case above is public, so you can run it yourself: prisma6-noinit and prisma-noinit in nk-repro.


Originally published, with updates as new versions ship, at nilaykabariya.blog. Written with AI assistance; every error and fix was reproduced on a real machine before it was written up.

Top comments (0)