Update for June 2024
See original solution below.
There are two options today that would work without disabling Yarn Plug'n'Play.
- Custom Prisma Output Directory
Prisma allows configuration of where it places the files of the generated client. To do so, set theoutputproperty in thegeneratorblock. It is best to also set the same path in your.gitignore.
generator client {
provider = "prisma-client-js"
output = "../src/generated/client"
}
Full Docs: https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/generating-prisma-client#using-a-custom-output-path
- Yarn PnPify
This acts as a middleman to redirect Prisma's output. See the comment from Moses Gamelli below for instructions.
After having tested a number of different things, I believe I have found a solution.
The Problem
The problem lies in how Yarn is resolving imports. Prisma CLI generates the client (by default) to node_modules/.prisma. Even when nodeLinker is set to node-modules, Yarn tries to resolve this import to .yarn/unplugged/<folder-name>, where the generated client does not exist.
The Solution
In order to fix this resolution problem, we have to create a custom resolution for the .prisma folder. This assumes that you do not have a custom output path.
# .yarnrc.yml
nodeLinker: node-modules
packageExtensions:
"@prisma/client@*":
dependencies:
".prisma": 'link:See "resolution" field of package.json'
# package.json
{
...
"resolutions": {
".prisma": "link:node-modules/.prisma"
}
}
Credit to this user on Github
Answer from Henrik VT on Stack OverflowUpdate for June 2024
See original solution below.
There are two options today that would work without disabling Yarn Plug'n'Play.
- Custom Prisma Output Directory
Prisma allows configuration of where it places the files of the generated client. To do so, set theoutputproperty in thegeneratorblock. It is best to also set the same path in your.gitignore.
generator client {
provider = "prisma-client-js"
output = "../src/generated/client"
}
Full Docs: https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/generating-prisma-client#using-a-custom-output-path
- Yarn PnPify
This acts as a middleman to redirect Prisma's output. See the comment from Moses Gamelli below for instructions.
After having tested a number of different things, I believe I have found a solution.
The Problem
The problem lies in how Yarn is resolving imports. Prisma CLI generates the client (by default) to node_modules/.prisma. Even when nodeLinker is set to node-modules, Yarn tries to resolve this import to .yarn/unplugged/<folder-name>, where the generated client does not exist.
The Solution
In order to fix this resolution problem, we have to create a custom resolution for the .prisma folder. This assumes that you do not have a custom output path.
# .yarnrc.yml
nodeLinker: node-modules
packageExtensions:
"@prisma/client@*":
dependencies:
".prisma": 'link:See "resolution" field of package.json'
# package.json
{
...
"resolutions": {
".prisma": "link:node-modules/.prisma"
}
}
Credit to this user on Github
If you're using yarn with pnp enabled:
- Install
@yarnpkg/pnpifyto dev dependencies - Prepend
yarn pnpifywith any prisma command e.gyarn pnpify prisma generate - Consider using a custom output path in your prisma schema