Reputation: 533
I am building an app using Next.js, Next-Auth, and Prisma. I am using API Routes for backend code. Recently, I upgraded Yarn on my pc to v3.1.1
. I then created a .yarnrc.yml
file and set the nodeLinker
option to "node-modules"
to avoid converting this project to PnP just yet.
When I run the dev server to work on my application, I run into this error as it tries to compile the next-auth API Route. Weirder yet, this issue does not occur when deployed via Vercel; the function logs are just fine and it works as expected.
Error: ENOENT: no such file or directory, open 'C:\Users\htech\Desktop\code\consulting\.yarn\unplugged\@prisma-client-virtual-d7adb716b6\node_modules\.prisma\client\schema.prisma'
When I search for similar issues, the usual solution that arises is setting a custom output path in schema.prisma
.
When I add a custom output path and update the imports accordingly, it just spits out some esoteric internal dependency error.
error - ./prisma/generated/runtime/index.js:27652:17
Module not found: Can't resolve '_http_common'
27650 | "../../node_modules/.pnpm/[email protected]/node_modules/undici/lib/node/http-parser.js"(exports2, module2) {
27651 | "use strict";
> 27652 | var common = require("_http_common");
yarn
:v3.1.1
next
: v12.1.0
@prisma/client
:v3.10.0
prisma
:v3.10.0
next-auth
:v4.2.1
This seems to be a simple issue with where it's generating to. However, I have no idea how to go about solving this issue, short of rolling back my systemwide version of yarn. Have I ran into a bug? Does anyone have a solution?
Upvotes: 1
Views: 4604
Reputation: 533
See original solution below.
There are two options today that would work without disabling Yarn Plug'n'Play.
output
property in the generator
block. It is best to also set the same path in your .gitignore
.generator client {
provider = "prisma-client-js"
output = "../src/generated/client"
}
After having tested a number of different things, I believe I have found a solution.
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.
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"
}
}
Upvotes: 5
Reputation: 61
If you're using yarn with pnp enabled:
@yarnpkg/pnpify
to dev dependenciesyarn pnpify
with any prisma command e.g yarn pnpify prisma generate
Upvotes: 2