✘ [ERROR] Could not resolve ".prisma/client/index-browser"
When i start my app and following the @prisma/nuxt tutorial i got this error
✘ [ERROR] Could not resolve ".prisma/client/index-browser"
node_modules/.pnpm/@prisma+client@6.15.0_prisma@6.15.0_magicast@0.3.5_typescript@5.9.2typescript@5.9.2/node_modules/@prisma/client/index-browser.js:1:23:
1 │ const prisma = require('.prisma/client/index-browser')
╵ ~~~~~~
You can mark the path ".prisma/client/index-browser" as external to exclude it from the bundle,
which will remove this error and leave the unresolved path in the bundle. You can also surround
this "require" call with a try/catch block to handle this failure at run-time instead of
bundle-time.
ERROR [unhandledRejection] Error during dependency optimization: 3:37:49 PM
✘ [ERROR] Could not resolve ".prisma/client/index-browser"
node_modules/.pnpm/@prisma+client@6.15.0_prisma@6.15.0_magicast@0.3.5_typescript@5.9.2typescript@5.9.2/node_modules/@prisma/client/index-browser.js:1:23:
1 │ const prisma = require('.prisma/client/index-browser')
╵ ~~~~~~
You can mark the path ".prisma/client/index-browser" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle. You can also surround this "require" call with a try/catch block to handle this failure at run-time instead of bundle-time.
at failureErrorWithLog (node_modules/.pnpm/esbuild@0.25.9/node_modules/esbuild/lib/main.js:1467:15)
at node_modules/.pnpm/esbuild@0.25.9/node_modules/esbuild/lib/main.js:926:25
at node_modules/.pnpm/esbuild@0.25.9/node_modules/esbuild/lib/main.js:1345:9
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
and i don't know how to fix them?
5 Replies
Hi @kora. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
It looks like Prisma’s browser entry is being picked up during Vite’s dependency optimization, which Nuxt then tries to bundle, causing the “Could not resolve .prisma/client/index-browser” error. The Nuxt docs suggest handling problematic ESM/CJS packages by transpiling or aliasing them so the correct entry is used during build. You can try:
- Transpile Prisma client to avoid Vite optimizing the wrong entry:
(Troubleshooting ESM Issues)
- If needed, alias the browser entry to the Node entry so bundling doesn’t try to resolve the browser build:
(Aliasing Libraries)
Note: Recent Nuxt work has focused on improving externals resolution for server builds, but if you’re on a version where Prisma resolution regresses, the above config is the recommended workaround until upstream fixes land in your setup (ensure externals are resolved first, resolve shared externals).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@637669517811515415> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
i got the same error with ur try
@kapa.ai i got the same error with ur code
Let me check the knowledge base for you again. One moment! :books:
----------------------
Thanks for confirming. Since the error persists, try both steps together and ensure they’re applied to the server only:
1) Transpile Prisma client
(Transpiling problematic deps is the advised workaround) (Troubleshooting ESM Issues).
2) Alias the browser entry to the Node entry
(Manual aliasing is suggested when a package resolves the wrong entry) (Aliasing Libraries).
Then:
- Delete node_modules and lockfile, reinstall.
- Run npx prisma generate.
- Clear Vite cache: rm -rf node_modules/.cache/vite.
- Restart dev server.
If imports are in nuxt.config.ts, use relative paths only (~/ and @/ aren’t supported there) (Config import paths). If the issue still occurs, it’s likely upstream resolution in Vite/Prisma; the Nuxt docs recommend transpile/alias as an interim fix until upstream patches land (Troubleshooting ESM Issues).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@637669517811515415> Kapa.ai is still learning and improving, please let me know how I did by reacting below.