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 13 - ENOENT: no such file or directory, open /var/task/.next/server/chunks/schema.prisma

See original GitHub issue

Bug description

When deploying a Next.js 13 (with app dir) on Vercel, I’m seeing the following error:

Error: ENOENT: no such file or directory, open '/var/task/.next/server/chunks/schema.prisma'
    at Object.openSync (node:fs:585:3)
    at Object.readFileSync (node:fs:453:35)
    at new LibraryEngine (/var/task/.next/server/chunks/538.js:28292:45)
    at PrismaClient.getEngine (/var/task/.next/server/chunks/538.js:32706:24)
    at new PrismaClient (/var/task/.next/server/chunks/538.js:32678:37)
    at Object.4963 (/var/task/.next/server/app/page.js:374:14)
    at __webpack_require__ (/var/task/.next/server/webpack-runtime.js:25:42)
    at page (/var/task/.next/server/app/page.js:237:87)
    at createComponentTree (/var/task/node_modules/next/dist/server/app-render.js:578:80)
    at /var/task/node_modules/next/dist/server/app-render.js:663:62 {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/var/task/.next/server/chunks/schema.prisma',
  clientVersion: '4.5.0',
  page: '/'
}
RequestId: 9ce84669-6d69-44b5-a6fc-f6e572a6a845 Error: Runtime exited with error: exit status 1
Runtime.ExitError

I’ve tried a few apps to try and reproduce this and this only happens when you make the page dynamic.

A few ways I’ve been able to reproduce this:

  1. Using the export const revalidate = 0 segment config on a page
  2. Calling headers() from “next/headers” inside the page.

✅ This works:

import { db } from "@/lib/db"

export default async function Page() {
  const messages = await db.message.findMany()

  return ...
}

❌ This does not work:

import { db } from "@/lib/db"

export const revalidate = 0 // 👈 Adding this results in the error above.

export default async function Page() {
  const messages = await db.message.findMany()

  return ...
}

❌ This does not work:

import { headers } from "next/headers"
import { db } from "@/lib/db"

export default async function Page() {
  headers() // 👈 Adding this results in the error above.

  const messages = await db.message.findMany()

  return ...
}

How to reproduce

I have a sample app here: https://github.com/shadcn/next-prisma-app

  1. Create a new Next.js 13 app with a prisma model.
  2. Create a new file at app/page.tsx and try calling prisma there.
  3. Add export const revalidate = 0
  4. Deploy to Vercel and try accessing the page at /
  5. You should the error above.
  6. Remove the export and try again.
  7. Error should be gone.

Expected behavior

Expected prisma to work with the segment config.

Prisma information

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["referentialIntegrity"]
}

datasource db {
  provider             = "mysql"
  url                  = env("DATABASE_URL")
  referentialIntegrity = "prisma"
}

model Message {
  id      Int     @id @default(autoincrement())
  content String?
}

Environment & setup

  • OS: Vercel (works fine locally on MacOS)
  • Database: MySQL
  • Node.js version: 16

Prisma Version

prisma                  : 4.5.0
@prisma/client          : 4.5.0
Current platform        : darwin
Query Engine (Node-API) : libquery-engine 0362da9eebca54d94c8ef5edd3b2e90af99ba452 (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli 0362da9eebca54d94c8ef5edd3b2e90af99ba452 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core 0362da9eebca54d94c8ef5edd3b2e90af99ba452 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt 0362da9eebca54d94c8ef5edd3b2e90af99ba452 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Format Wasm             : @prisma/prisma-fmt-wasm 4.5.0-43.0362da9eebca54d94c8ef5edd3b2e90af99ba452
Default Engines Hash    : 0362da9eebca54d94c8ef5edd3b2e90af99ba452
Studio                  : 0.476.0
Preview Features        : referentialIntegrity

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:17 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
leerobcommented, Nov 6, 2022

^ Prisma is now added to the default list, I’ve updated the docs there to reflect that.

6reactions
FlatMapIOcommented, Nov 5, 2022

I’ve temporarily generated the prisma-client to src dir, bypassing this problem

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["referentialIntegrity", "interactiveTransactions"]

  output = "../shared/prisma-client"
}

db.ts

import { PrismaClient } from "@/shared/prisma-client";
Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
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 >
How to fix NextJS enoent? - Stack Overflow
I'd the same problem, in my case i just try it: PS. this fix is not permanent, this is just a stopgap solution....
Read more >
An open source application built using the new router, server ...
Prisma: Error: ENOENT: no such file or directory, open '/var/task/.next/server/chunks/schema.prisma' · Next.js 13: Client side navigation does ...
Read more >
ENOENT: no such file or directory when deployed to Vercel
Nothing too major, but one of the things I decided to do was to bump my current Nextjs version from the version I...
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