question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

next.js ENOENT trying to open schema.prisma

See original GitHub issue

Bug description

In a monorepo, when exporting PrismaClient from one package and consuming it in a next.js api route, I get

error - Error: ENOENT: no such file or directory, open 'C:\Users\sbere\Desktop\Projects\prisma-pnpm-workspace-test\apps\frontend\.next\server\pages\api\schema.prisma'

How to reproduce

  1. Git clone https://github.com/SimonBerens/prisma-pnpm-workspace-test
  2. run
pnpm install
cd packages/prisma
pnpx prisma generate
cd ../../apps/frontend
pnpm run dev
  1. send a GET request to localhost:3000/api/hello

Expected behavior

The api runs as expected

Prisma information

prisma:tryLoadEnv Environment variables not found at null +0ms
  prisma:tryLoadEnv Environment variables not found at undefined +0ms
  prisma:tryLoadEnv No Environment variables loaded +1ms
  prisma:tryLoadEnv Environment variables not found at null +1ms
  prisma:tryLoadEnv Environment variables not found at undefined +0ms
  prisma:tryLoadEnv No Environment variables loaded +0ms
  prisma:client dirname C:\Users\sbere\Desktop\Projects\prisma-pnpm-workspace-test\apps\frontend\.next\server\pages\api +0ms
  prisma:client relativePath ..\..\..\..\..\..\packages\prisma +0ms
  prisma:client cwd C:\Users\sbere\Desktop\Projects\prisma-pnpm-workspace-test\packages\prisma +0ms
  prisma:client clientVersion: 3.12.0 +2ms
  prisma:client clientEngineType: library +0ms

Environment & setup

  • OS: Windows 11
  • Database: PostgreSQL
  • Node.js version: v16.14.2

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:open
  • Created a year ago
  • Reactions:11
  • Comments:21

github_iconTop GitHub Comments

20reactions
remorsescommented, Jun 11, 2022

I fixed this adding to .npmrc the following, this forces the prisma package to remain on top of the monorepo i think

public-hoist-pattern[]=*prisma*
7reactions
lottamuscommented, Nov 6, 2022

If you’re using nextjs v13, try adding prisma to the serverComponentsExternalPackages in your config:

// next.config.js
const nextConfig = {
  experimental: {
    appDir: true,
    serverComponentsExternalPackages: ['@prisma/client'],
  },
};

https://beta.nextjs.org/docs/api-reference/next.config.js#servercomponentsexternalpackages

image
Read more comments on GitHub >

github_iconTop Results From Across the Web

Best practice for instantiating PrismaClient with Next.js
Solution. The solution in this case is to instantiate a single instance PrismaClient and save it on the global object. Then we keep...
Read more >
Taxonomy - Vercel
~Prisma: Error: ENOENT: no such file or directory, open '/var/task/.next/server/chunks/schema.prisma'~; ~Next.js 13: Client side navigation does not update head ...
Read more >
ENOENT: no such file or directory, open '/var/task/src/schema ...
I've been trying to get deploy an app running express, ts & prisma, using serverless. I keep running into the following error:
Read more >
An open source application built using the new router, server ...
GitHub authentication (use email); Prisma: Error: ENOENT: no such file or directory, open '/var/task/.next/server/chunks/schema.prisma' ...
Read more >
shadcn on Twitter: "Found a temp fix for the @prisma on ...
Next.js 13 - ENOENT: no such file or directory, open /var/task/.next/server/chunks/schema.prisma ·... Bug description When deploying a Next.js 13 (with app ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found