prisma: 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 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:
- Using the
export const revalidate = 0
segment config on a page - 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
- Create a new Next.js 13 app with a prisma model.
- Create a new file at
app/page.tsx
and try calling prisma there. - Add
export const revalidate = 0
- Deploy to Vercel and try accessing the page at
/
- You should the error above.
- Remove the export and try again.
- 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
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 19 (4 by maintainers)
^ Prisma is now added to the default list, I’ve updated the docs there to reflect that.
I’ve temporarily generated the prisma-client to src dir, bypassing this problem
db.ts
If you’re using nextjs, try adding prisma to the
serverComponentsExternalPackages
in your config:https://beta.nextjs.org/docs/api-reference/next.config.js#servercomponentsexternalpackages
I’ve updated the issue description with more details. I found out this happens when you opt into dynamic pages. Example by using a segment config or using
headers()
orcookies()
.I can confirm the reproduction that @shadcn shared originally (13.0.2 a monorepo, app dir, no custom
output
inschema.prisma
), and I can also reproduce that it has been fixed with next@13.0.2 as @leerob shared. Thanks!For everyone who commented here but is actually using a monorepo or a custom
output
config inschema.prisma
, we have quite a few issues for your case. Some examples: https://github.com/prisma/prisma/issues/12853 https://github.com/prisma/prisma/issues/12921 https://github.com/prisma/prisma/issues/12823 Please subscribe to these for updates (which we fortunately will be able to post soon 🔜).I think this issue can be closed as it is resolved by adding
serverComponentsExternalPackages: ['@prisma/client']
into the next config. (https://github.com/prisma/prisma/issues/16117#issuecomment-1304673449)For me this workaround brings another error which it searches for schema file inside default
node_modules
dir.@FlatMapIO It worked. THANK YOU 🙌
I meant this new segment config in the beta docs: https://beta.nextjs.org/docs/api-reference/segment-config#revalidate
I’m also experiencing the same error, I have a monorepo and prisma lives in a different package than the nextjs app. None of the suggestions above work for me.