'Using Prisma with Yarn v3
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");
Environment
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?
Solution 1:[1]
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"
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |