Invalid module ".prisma" is not a valid package name imported from C:\source\nuxt\node_modules\@pris
I've pulled down the sample project from https://github.com/prisma/prisma-examples/tree/latest/orm/nuxt
I haven't changed anything.
When I try to build it with npm build, I get this error:
Invalid module ".prisma" is not a valid package name imported from C:\source\nuxt\node_modules@prisma\client\default.js
I've found and tried to use the suggested fix of putting this code in my nuxt.config.ts
vite: {
resolve: {
alias: {
'.prisma/client/index-browser': './node_modules/.prisma/client/index-browser.js',
},
},
},
But this does not work at all for me, I'm still getting the exact same build error.
If I go into the node_modules folder and fully comment out the one line that's in index-browser.js, it builds. But I don't want to be manually editing node modules all of the time.
The sample project uses these dependencies
"@prisma/client": "6.9.0",
"@prisma/extension-accelerate": "2.0.2",
"nuxt": "3.17.6"
GitHub
prisma-examples/orm/nuxt at latest Ā· prisma/prisma-examples
š Ready-to-run Prisma example projects. Contribute to prisma/prisma-examples development by creating an account on GitHub.
1 Reply
You opted for speed from this bot. Let's conjure up an answer right now!
The error
Try the absolute path alias with
Invalid module ".prisma" is not a valid package name imported from .../node_modules/@prisma/client/default.js is a known issue when using Prisma with Nuxt 3, especially with recent versions of Nuxt and Prisma. The alias fix for .prisma/client/index-browser in nuxt.config.ts is widely suggested, but it does not always resolve the issue, particularly with certain package manager setups or on Windows.
Key points and solutions from the knowledge sources:
1. Alias Fix (with Absolute Path):
The alias you tried is correct in principle, but some users report it only works reliably when using an absolute path. You can use Nuxt's resolver to ensure the path is absolute:
This approach is recommended in both the Prisma docs and user reports, especially when using pnpm or when other plugins (like @nuxt/i18n) are involved. It ensures Vite resolves the alias correctly regardless of your environment or package manager [source].
2. Check for Custom Prisma Client Output:
If your schema.prisma uses a custom output for the client generator, you must import the client from that output path, not from @prisma/client. The Nuxt Prisma module expects the default output location. Remove any custom output if possible [source].
3. Nitro Externals Workaround:
Some users report success by adding the following to nuxt.config.ts:
This can help with SSR builds that otherwise fail due to module resolution issues [source].
4. Prisma/Nuxt Compatibility:
There are ongoing fixes in the Prisma dev branch for Nuxt compatibility. If possible, try the latest Prisma version or check the prisma-examples/nuxt3-starter-nodejs branch for updates [source].
Summary:Try the absolute path alias with
createResolver, ensure you are not using a custom Prisma client output, and consider the Nitro externals workaround. If the issue persists, it may be due to unresolved compatibility bugs, in which case monitoring the latest Prisma releases and example branches is advised.
ā
Great, thanks for letting us know that this solved your question!