Support for Yarn 2+ with PnP
See original GitHub issueWhen trying to run prisma2 init
via yarn dlx
it fails in the following way:
Getting the same behavior when having installed prisma2
as a local dev dependency:
I’m using yarn 2.0.0-rc.27
Issue Analytics
- State:
- Created 4 years ago
- Reactions:48
- Comments:48 (11 by maintainers)
Top Results From Across the Web
Plug'n'Play | Yarn - Package Manager
Unveiled in September 2018, Plug'n'Play is an innovative installation strategy for Node. Based on prior work in other languages (for example autoload for...
Read more >Support Yarn 2 PnP · Discussion #4223 · vercel ... - GitHub
I think Vercel should make it clear that it works with Yarn 2+, as long as you don't use PnP. And Vercel should...
Read more >Upgrade to Yarn >2 with (or without) Plug'n'Play | by Julien ...
A yarn install is even faster with PnP, because there is no node_modules directory to copy the zipped files into. Instead, with PnP...
Read more >Yarn v2 PnP is simply a lifesaver if you have a medium+ sized ...
That said, I think yarn 2's PnP + zero installs ... relates to the fact that TS does not have native support for...
Read more >Yarn 2, Yarn 3, PNP, and our migration journey - Jakub Zitny
At our second Productboard Frontend Meetup, the Software Engineer from Deepnote - Jakub Zitny, talked about Yarn 2, Yarn 3, PNP, and their ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you @Globolobo + @darioblanco for putting me on the right path! I compiled this year-of-2022 note since no one suggestion above worked perfectly for me with Next + Vercel + Yarn 3 + Yarn PnP + Yarn Zero Install. Here’s my setup.
In
package.json
I use pnpify with a script to wrap generation. I also run generation as part of myyarn build
. Nothing fancy with module resolution needed.In my
prisma/schema.prisma
, I set a relative output path (this can be anything, I’m just putting it into my server api folder). It just needs to be withinsrc
.I make sure to ignore that path for version control (and prettier/eslint/anything else) in
.gitignore
/etcAnd finally, in my
.ts
files, I just import from my custom path instead of from the main package. Works great!or
Notes
If your package resolution requires a relative path like
../../api/...
or a prefix like@app/api/...
, that should work fine instead, I just useapi/...
directly since I set that up as a top level path.You could avoid putting the generate command in your build command if you check the generated folder into version control, but I didn’t think that was worth it. If you don’t check it in, then Vercel/whatever will fail the build since it’ll be missing until you run generation again. As my DB should always be up and accessible, I see no problem with generating from Vercel before I build. Catches breaking changes anyway.
Quick update
We’d like to add support for Yarn 2, but not right now. Yarn 2 is a significant departure from other Node package managers (no node_modules!). By default, Prisma Client relies on the presence of node_modules, so we need to figure out how to first detect Yarn 2 and then apply a Yarn 2-specific solution.
This is all totally doable, but it will just take time. Right now we’re focused on adding more powerful query features to the Prisma Client.
PRs to fix this are very welcome of course!
Workaround
In the meantime, you can workaround this issue by providing a custom output path.
prisma/schema.prisma
main.ts
You can read more about this feature here: https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/generating-prisma-client#specifying-a-custom-output-path