pnpm workspace + nextjs: ENOENT: no such file or directory, open '...\.next\server\pages\api\schema.prisma'
See original GitHub issueBug description
I have a pnpm workspace with three projects:
- / -root project
- /packages/database - Prisma installed as a dependency, re-export generated prisma client
- /packages/next - A standard next.js typescript template, importing the database project
When I run the next project I get this error:
error - Error: ENOENT: no such file or directory, open 'C:\Users\hkhen\dev\pnpm-next\packages\next\.next\server\pages\api\schema.prisma'
I’ve tried a few variations: prisma and @prisma/client 3.12.0 and 3.13.0-dev.15, standard output directory and output = "../src/generated/prisma"
, all give the same error.
It sounds like this is kind of the same error as #10361, but it seems like next.js does something special handling of dirname. Regular node-js server apps works fine with the same setup.
How to reproduce
Terminal 1:
git clone git@github.com:ineentho/pnpm-nextjs-repro.git
cd pnpm-nextjs-repro
pnpm i # prisma generate runs as a postinstall hook
pnpm start # run next in dev-mode
Termnal 2:
curl localhost:3000/api/hello
The first terminal will log the error:
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
wait - compiling...
event - compiled client and server successfully in 643 ms (124 modules)
wait - compiling /api/hello...
wait - compiling...
warn - ../database/src/generated/prisma/runtime/index.js
Module not found: Can't resolve 'encoding' in 'C:\Users\hkhen\dev\pnpm-nextjs-repro\packages\database\src\generated\prisma\runtime'
2022-04-16T15:35:50.611Z prisma:tryLoadEnv Environment variables not found at null
2022-04-16T15:35:50.612Z prisma:tryLoadEnv Environment variables not found at undefined
2022-04-16T15:35:50.612Z prisma:tryLoadEnv No Environment variables loaded
2022-04-16T15:35:50.631Z prisma:tryLoadEnv Environment variables not found at null
2022-04-16T15:35:50.631Z prisma:tryLoadEnv Environment variables not found at undefined
2022-04-16T15:35:50.631Z prisma:tryLoadEnv No Environment variables loaded
2022-04-16T15:35:50.631Z prisma:client dirname C:\Users\hkhen\dev\pnpm-nextjs-repro\packages\next\.next\server\pages\api
2022-04-16T15:35:50.631Z prisma:client relativePath ..\..\..\prisma
2022-04-16T15:35:50.632Z prisma:client cwd C:\Users\hkhen\dev\pnpm-nextjs-repro\packages\next\.next\server\pages\api
2022-04-16T15:35:50.634Z prisma:client clientVersion: 3.12.0
2022-04-16T15:35:50.634Z prisma:client clientEngineType: library
error - Error: ENOENT: no such file or directory, open 'C:\Users\hkhen\dev\pnpm-nextjs-repro\packages\next\.next\server\pages\api\schema.prisma'
warn - ../database/src/generated/prisma/runtime/index.js
Module not found: Can't resolve 'encoding' in 'C:\Users\hkhen\dev\pnpm-nextjs-repro\packages\database\src\generated\prisma\runtime'
wait - compiling /_error (client and server)...
wait - compiling...
warn - ../database/src/generated/prisma/runtime/index.js
Module not found: Can't resolve 'encoding' in 'C:\Users\hkhen\dev\pnpm-nextjs-repro\packages\database\src\generated\prisma\runtime'
2022-04-16T15:35:50.868Z compression no compression: not acceptable
Environment & setup
- OS: Windows 10
- Database: Postgres
- Node.js version: v17.3.0
Prisma Version
prisma : 3.12.0
@prisma/client : 3.12.0
Current platform : windows
Query Engine (Node-API) : libquery-engine 22b822189f46ef0dc5c5b503368d1bee01213980 (at ..\..\node_modules\.pnpm\@prisma+engines@3.12.0-37.22b822189f46ef0dc5c5b503368d1bee01213980\node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine : migration-engine-cli 22b822189f46ef0dc5c5b503368d1bee01213980 (at ..\..\node_modules\.pnpm\@prisma+engines@3.12.0-37.22b822189f46ef0dc5c5b503368d1bee01213980\node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core 22b822189f46ef0dc5c5b503368d1bee01213980 (at ..\..\node_modules\.pnpm\@prisma+engines@3.12.0-37.22b822189f46ef0dc5c5b503368d1bee01213980\node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary : prisma-fmt 22b822189f46ef0dc5c5b503368d1bee01213980 (at ..\..\node_modules\.pnpm\@prisma+engines@3.12.0-37.22b822189f46ef0dc5c5b503368d1bee01213980\node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : 22b822189f46ef0dc5c5b503368d1bee01213980
Studio : 0.459.0
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Next.js + pnpm + dgraph-js-http v20.07.2 = doesn't work
So, I recently tried to integrate my Next.js app with the recently ... internal/fs/utils.js:308 throw err; ^ Error: ENOENT: no such file or...
Read more >next.js ENOENT trying to open schema.prisma - bytemeta
In a monorepo, when exporting PrismaClient from one package and consuming it in a next.js api route, I get error - Error: ENOENT:...
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 FreeTop 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
Top GitHub Comments
Possible workaround Context, I’m using PNPM workspaces and my prisma config is in a packages that is used by a Nest.js app. The Nest.js app bundle the generated Prisma build with. webpack.
In post build of
prisma generate
, I run the following script and it’s doing the trick (for now). IfregularDirname
variable name is changed, the script will need an updateI faced the same problem for the past 2 days and I make it work and i don’t know why but here is the code of my singleton PrismaClient.
the previous singleton PrismaClient
Environment
Could anyone explain why it worked ?