prisma
prisma copied to clipboard
Error nuxt / prisma : Invalid module ".prisma" is not a valid package name imported from ...\node_modules\@prisma\client\default.js
Hi everyone, i'm working on a personnal web project with nuxt and prisma. When i try to build my project i have this error (title). I tried several solutions to solve it but none worked. Maybe i made a mistake ? Can i get some help ?
Here are some files that may be useful:
package.json : { "name": "nuxt-app", "private": true, "type": "module", "scripts": { "build": "nuxt build", "dev": "nuxt dev", "generate": "nuxt generate", "preview": "nuxt preview", "postinstall": "nuxt prepare" }, "dependencies": { "@prisma/client": "^6.8.2"? "nuxt": "^3.16.2", " }, "devDependencies": { "prisma": "^6.8.2",
} }
nuxt.config;ts : export default defineNuxtConfig({ compatibilityDate: '2024-11-01', devtools: { enabled: true }, css: ['~/assets/css/main.css'], components: true, postcss: { plugins: { tailwindcss: {}, autoprefixer: {}, }, }, plugins: ['~/plugins/pinia.js'], modules: [ '@vueuse/nuxt' ], build: { transpile: ['@motionone/vue'] } })
prisma.ts : import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
export default prisma;
schema.prisma : generator client { provider = "prisma-client-js" }
datasource db { provider = "mysql" url = env("DATABASE_URL") }
ERROR Invalid module ".prisma" is not a valid package name imported from ...\node_modules@prisma\client\default.js
The same issue
I had the same problem — this comment helped:
https://github.com/prisma/prisma/issues/26565#issuecomment-2744265244
https://github.com/prisma/prisma/issues/26565#issuecomment-2756914379
This resolved the problem on my end.
Invalid module ".prisma" is not a valid package name imported from …\node_modules@prisma\client\default.js
Because the build failed, Netlify never published a site and there’s no live URL yet.
I’m preparing a quick patch for the Vinxi / Vite config to mark “.prisma” (not just “.prisma/client”) as external in the SSR bundle; once we rebuild with that change the deploy should complete. I’ll push the fix and let you know the next exact build+deploy command to run.
Anybody has any idea on how to fix it. Windsurf agent is stuck. It searched the web, github etc.
I managed to get the build to work locally by adding this to my nuxt.config.ts:
nitro: {
externals: {
trace: false
include: ['@prisma/client'],
},
},
How do you guys run your seed command? I get the same kind of errors when using jiti/tsx/ts-node to invoke the seed script.
@jakepetrovic1979
Invalid module ".prisma" is not a valid package name imported from …\node_modules@prisma\client\default.js
This error may occur if your schema.prisma contains the following generator configuration:
generator client {
provider = "prisma-client"
output = "../app/generated/prisma"
previewFeatures = ["driverAdapters", "queryCompiler"]
}
but your import statements still reference Prisma the old way:
// Before
import { Prisma } from '@prisma/client';
// After
import { Prisma } from '~/generated/prisma/client';
You can take a look at this article and solve the corresponding problem very efficiently, which is better than all the solutions I have seen. csdn文章链接
I solved it using @DesertCookie solution + resolver, because when not using resolver it's working for build but not when running it.
import { createResolver } from '@nuxt/kit';
const resolver = createResolver(import.meta.url);
export default defineNuxtConfig({
....
vite: {
resolve: {
alias: {
'.prisma/client/index-browser': resolver.resolve(
'./node_modules/.prisma/client/index-browser.js'
),
'.prisma/client/default': resolver.resolve(
'./node_modules/.prisma/client/default.js'
),
},
},
},
nitro:{
externals: {
trace: false,
inline: ['@prisma/client'],
},
}
If I use vite.resolve.alias as above, during prerendering I get
[10:42:04] ERROR Invalid module ".prisma/client/default" is not a valid package name imported from .nuxt\prerender\index.mjs.
If I move the alias to nitro.alias, I get instead
ERROR [unhandledRejection] Cannot read properties of undefined (reading 'bind') 10:44:07
at Qr.wrapEngine (node_modules.pnpm@[email protected]_prism_9ddcb10fcbc168becda139e3686af05a\node_modules@prisma\client\runtime\library.js:111:10611) at Qr.loadEngine (node_modules.pnpm@[email protected]_prism_9ddcb10fcbc168becda139e3686af05a\node_modules@prisma\client\runtime\library.js:112:749) at async Qr.instantiateLibrary (node_modules.pnpm@[email protected]_prism_9ddcb10fcbc168becda139e3686af05a\node_modules@prisma\client\runtime\library.js:111:11869) ERROR [unhandledRejection] Cannot read properties of undefined (reading 'bind') 10:44:07
at Qr.wrapEngine (node_modules.pnpm@[email protected]_prism_9ddcb10fcbc168becda139e3686af05a\node_modules@prisma\client\runtime\library.js:111:10611) at Qr.loadEngine (node_modules.pnpm@[email protected]_prism_9ddcb10fcbc168becda139e3686af05a\node_modules@prisma\client\runtime\library.js:112:749) at async Qr.instantiateLibrary (node_modules.pnpm@[email protected]_prism_9ddcb10fcbc168becda139e3686af05a\node_modules@prisma\client\runtime\library.js:111:11869)
It is not possible to use nuxt V4 with prisma, it's been a month and patch is not released yet. You better use another library for the future of your project. I am really sick of errors of this package, it's fully random. If you get it into working, it may not work tomorrow.
Someone from dev team said they have fixed it, but even the official module is not using the version that proposes the actual fix.
I have noticed it's not good idea to
Try your luck with this, worked for me.
/prisma/schema.prisma:
generator client {
provider = "prisma-client"
output = "../prisma/generated/client" // DO NOT USE /app, must be standalone dir
}
run prisma generate
and
/server/db.ts:
import { PrismaClient } from "../prisma/generated/client/client";
const prisma = new PrismaClient();
export default prisma;
then you can use it in your /server just like this:
import prisma from "~~/server/db";
If you have any option related with prisma inn your nuxt config, remove it.
I hope they release the patch as soon as possible, i am sure no one in V4 has managed to use it without workaround (or even with workaround)
Edit: Another error just came up, not surprising.
D:\Code\--DEVELOPMENT\iftk>bun .output/server/index.mjs
Listening on http://[::]:3000
[request error] [unhandled] [POST] http://localhost:3000/api/auth/register
1194 | unhandled = false;
1195 | statusMessage;
1196 | data;
1197 | cause;
1198 | constructor(message, opts = {}) {
1199 | super(message, opts);
^
error: "process" has already been declared
cause: 1 | import process from 'node:process';globalThis._importMeta_=globalThis._importMeta_||{url:"file:///_entry.js",env:process.env};import * as process from 'node:process';
^
error: "process" has already been declared
at D:\Code\--DEVELOPMENT\iftk\.output\server\chunks\_\db.mjs:1:139
1 | import process from 'node:process';globalThis._importMeta_=globalThis._importMeta_||{url
^
note: "process" was originally declared here
at D:\Code\--DEVELOPMENT\iftk\.output\server\chunks\_\db.mjs:1:8,
statusCode: 500,
fatal: false,
unhandled: true,
statusMessage: undefined,
data: undefined,
at new H3Error (D:\Code\--DEVELOPMENT\iftk\.output\server\chunks\_\nitro.mjs:1199:5)
at createError$1 (D:\Code\--DEVELOPMENT\iftk\.output\server\chunks\_\nitro.mjs:1225:15)
at <anonymous> (D:\Code\--DEVELOPMENT\iftk\.output\server\chunks\_\nitro.mjs:2697:21)
Hi @arshx86, do you have a reproducible Nuxt 4 project that fails with Prisma 6.15.0 and the prisma-client generator?
If so, please share it with us. We're aiming to release an official Nuxt 4 example by September 9th (the Prisma 6.16.0 release date).
Please understand that all web frameworks and bundlers behave differently, and often do not stick to the official ECMAScript specification or WinterCG directives (you can learn more on that topic here). At times, this non-standard frameworks are more popular than others that do a good job at sticking with the web standards, which means their support takes priority in our backlog.
Thanks!
Hi @arshx86, do you have a reproducible Nuxt 4 project that fails with Prisma 6.15.0 and the
prisma-clientgenerator? If so, please share it with us. We're aiming to release an official Nuxt 4 example by September 9th (the Prisma 6.16.0 release date).Please understand that all web frameworks and bundlers behave differently, and often do not stick to the official ECMAScript specification or WinterCG directives (you can learn more on that topic here). At times, this non-standard frameworks are more popular than others that do a good job at sticking with the web standards, which means their support takes priority in our backlog.
Thanks!
Hi, no everything works perfect now. Ill leave my working repo if anyone needs it.
https://github.com/arshx86/NuxtQuick
No issue anymore.
Closing this as solved, as it is no longer an issue with the prisma-client generator.
I've also posted a Nuxt 4 example here: https://github.com/prisma/prisma-examples/tree/latest/generator-prisma-client/nuxt4-starter-nodejs.
Thanks!