-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Fails to resolve @prisma/client with Vite v6 #12610
Comments
This is a Prisma issue with packaging and Vite handles it, not an issue with React Router. You can work around this by importing the default explicitly or importing as a default-less module: prisma/prisma#6491 (comment) |
Are you sure that this is a current Prisma issue? I was barely able to find issues of people complaining about this on Prisma, the linked issue is 3 years old, and none of the solutions there are working for me. Prisma packaging has changed a lot since that issue, it used to be CJS-only, now it's dual publish and supports all kinds of environments. And with the latest version publint doesn't report significant problems. Also, as I described in my bug report, I'm not running into this issue in Vite v6 alone: https://github.com/silvenon/repro/tree/vite-v6-prisma-client, nor in Vite v5 + React Router. This is why I suspect that there is something that React Router does that doesn't work well with how Vite v6 resolves Prisma. Note that In my example with only Vite v6 + Prisma I'm using Environment API, maybe this makes some kind of a difference in resolution 🤷♂️ |
I mean, I can understand the strong suspicion towards Prisma packaging, I really wanted to find some kind of a problem there because if there was a problem with how React Router loads modules wouldn't other modules be failing to resolve as well? Why just Prisma, weird… I guess I need to go dig deeper, I would just appreciate some pointers regarding which API for loading modules I need to look into for this. Just regular |
none of this solution works for dev run
this works for prod build only |
solution if anyone looks for it is to add
in schema.prisma then run npx prisma generate and in vite config
replace randomdbname with whatever |
So by default this? ssr: {
optimizeDeps: {
include: ["./node_modules/.prisma/client"],
},
}, Unfortunately it didn't work for me either. In my repro could you tell me which steps exactly I need to do to get it working? Just in case I also tried generating to a non-dot path using the recommended |
that doesn't work since vite6 has some issue with path starting . so my solution bypasses that oh and you need to replacte all imports in yuor code from |
Stripping away Maybe for some reason it works for you, but I can't know the specifics of your setup without a working demo. |
|
But there's no bug for me with Vite v6 + Prisma alone, only when React Router is involved, so this is the repro that needs to be fixed: https://github.com/silvenon/repro/tree/react-router-v7-vite-v6-resolve-prisma-client |
My apologies, a similar fix would've worked for the React Router repro. I didn't think I also needed to update all of my imports, I thought that the This workaround seems to solve the issue. I would've still liked to know what caused it so that I can properly report it to the appropriate project, but it's difficult to know where to look. Thanks for your help! |
something with vite aliases and '.' handling in path |
My guess is that this breaking change in Vite v6 is affecting your case.
and that removes all default conditions. Maybe a plugin like this can be used as a workaround. import { defaultClientConditions, defaultServerConditions } from 'vite'
const p = {
name: 'foo',
enforce: 'post',
config() {
return {
resolve: {
conditions: [...defaultClientConditions],
},
ssr: {
resolve: {
conditions: [...defaultServerConditions]
}
}
}
}
} |
Wow, very nice catch, thank you so much! ❤️ Now Now I know where to look 💪 @sapphi-red will you do the honors of submitting the fix for
|
@timdorr considering that my suspicions were true that the transition to Vite v6 is incomplete, could you reopen the bug report for now? At least until fix for |
It'll take some time to make a PR for me so feel free to create one instead of me🙂 |
I managed to get prisma working with Vite6 using... import { remember } from "@epic-web/remember" This is my db.server.ts file and import everything from this file. |
Perhaps in the near future Prisma will update to address this issue. In the meantime, I've found that changing my |
Indeed, thanks for the workaround, resolve: {
alias: {
"@prisma/client": "@prisma/client/index.js"
}
} Perhaps fixing the root problem of resolving the module will also fix the failure to evaluate it. I'll get around to submitting a PR soon. |
Just like in the PR, the final missing ingredient was configuring |
I'm using React Router as a...
framework
Reproduction
https://github.com/silvenon/repro/tree/react-router-v7-vite-v6-resolve-prisma-client
Clone the repository:
Install dependencies and set up Prisma:
The issue is present both in development and in build:
System Info
Used Package Manager
npm
Expected Behavior
Expected to be able to upgrade to React Router v7.1.0 and to Vite v6, and have my app working as usual.
Actual Behavior
With Vite v6 it's failing to resolve
@prisma/client
both in dev and build.Before v7.1.0 I had the same problem when I tried upgrading Vite to v6, so I was wondering what went wrong, but then I saw that you were still working on Vite v6 support so I assumed it was because of that, however unfortunately the problem remained.
I tried using Environment API to import
@prisma/client
in Vite v6 SSR without React Router involved, and it worked, so I think this has something to do with how React Router is using Vite.The text was updated successfully, but these errors were encountered: