-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prisma client could not be resolved #19036
Comments
More simple reproduction: https://stackblitz.com/edit/github-jxnpwg49?file=server%2Fapp.ts,vite.config.ts,package.json&terminal=build (needs to run locally as prisma does not work in stackblitz) It seems prisma generates For a workaround, you can change the location.
and update the import to use |
Not sure this is actionable for us either. Just to note, this repro is on Vite 5, but there is a prisma related issue with Vite 6 as well in remix-run/react-router#12610. |
I changed the output as
and also changed the import as While building vite said this
and the server logs on vercel have this error
Is there something that i am missing? |
This issue is unrelated to remix-run/react-router#12610, in there React Router misconfigures Vite v6, so it fails to resolve I tried various combinations of solutions, but Vite refuses to bundle the generated The only thing that seems to have worked was patching both Btw, prisma/prisma#21094 seems related to this issue. |
I found that rebasing all import { defineConfig } from "vite";
export default defineConfig({
plugins: [
{
name: "prisma;rebase",
enforce: "pre",
transform(code, id) {
if (id.includes("@prisma/client")) {
return code.replaceAll(
/require\((['"])\.prisma\/client/g,
"require($1../../.prisma/client",
);
}
},
},
{
name: "prisma:dirname",
transform(code, id) {
if (id.includes("@prisma/client") || id.includes(".prisma/client")) {
return code.replaceAll("__dirname", "import.meta.dirname");
}
},
},
],
build: {
ssr: "./server/app.ts",
},
ssr: {
noExternal: true,
},
}); The question now is whether this is something that Vite is willing to fix, or whether I should submit a request for ESM build to Prisma with this use case as an example, or both. |
@silvenon apologies for the delay, i implemented this plugin and it did work during the local build, i did not see any weird errors/warnings. I deployed this change to vercel and things aren't working there yet. This was the error message in the logs
|
For some reason importing This is not a React Router issue because the same issue is present in the StackBlitz demo without React Router as well. You can work around it by forcing the return code.replaceAll(
/require\((['"])\.prisma\/client\/default/g,
"require($1../../.prisma/client/index"
); Also, I recommend moving the Prisma plugins before the React Router plugin, to be on the safe side. |
this is how i set up the plugins
while building it locally it said
|
The error is misleading, it is a module, because as soon as I don't use So this is out of my league, sorry. I don't know where the root of these problems is, whether it's Vite's CommonJS interoperability, or Prisma's CJS-only exports (prisma/prisma#21858), or both. |
For quick debugging in your project you don't have to actually run the thing on Vercel, I ran:
and got the same error. That way you can iterate on your solution more quickly. |
And considering Prisma's very slow movement towards ESM I recomend to both of us that we try out Drizzle, if that's a viable option for you. |
Wow that's really helpful, thank you so much, I really appreciate your help and efforts ❤️ |
You're welcome, it was an interesting problem to try to solve, too bad it didn't work out, though. I'll try to isolate the issue and report it separately to Vite. |
What you can do to help is include bundling as a detail in your title because that's important. That way people won't think that Vite is generally failing to resolve Prisma. Some examples:
Or leave as-is, your choice. |
{
name: "prisma:build",
apply: "build",
config() {
return {
define: {
__dirname: "import.meta.dirname",
__filename: "import.meta.filename",
},
};
},
transform(code, id) {
if (id.includes("@prisma/client-generated")) {
return code.replace('eval("__dirname")', "import.meta.dirname");
}
},
}, This is the only plugin needed now. Possibly the only remaining problem that you might have during runtime is missing Prisma binary, for example If you're still interested in pursuing this problem, let me know how it goes. |
@sapphi-red I don't think there's anything that Vite is doing wrong here. Unless you have plans to support imports to It's funny how far I went only to figure out that the workaround you initially recommended was the best way 😄 |
Describe the bug
I started with a default vercel template for react router v7, deployed it on vercel, everything works. Now when i add prisma and start the build, vite says
".prisma/client/default" is imported by ".prisma/client/default?commonjs-external", but could not be resolved – treating it as an external dependency.
and deployment crashes with an internal server error.I had already raised this issue on react-router but they closed it saying that this isn't a react router bug
Reproduction
https://github.com/dhruvkaushik305/testing-prisma.git
Steps to reproduce
run
npm run build
and the cli shows that error messageSystem Info
Used Package Manager
npm
Logs
These are the server logs on vercel
Validations
The text was updated successfully, but these errors were encountered: