Repository navigation
User questions: Bundler error #19351
Description
Activity
Which package manager are you using?
Package manager:
pnpm
Version:8.5.1Is your workspace a monorepo setup?
Monorepo with
turborepoIs a bundler in use? If yes, which one?
Native Next.js bundler
Is a framework in use? If yes, which one?
Next.js
Version:13.4.4Your project uses TypeScript or just JavaScript?
TypeScript only
When you saw our message, did it happen locally or in deployment?
Locally
Where is your project deployed?
Not deployed yet
How can we reproduce this?
This is inside a
route.tsin the new App-router from Next.jstype Props = { params: { brandId: string; }; }; export async function GET(req: Request, { params: { brandId } }: Props) { if (!brandId) { return NextResponse.json( { error: "Brand ID is required" }, { status: 400 } ); } const id = parseInt(brandId); if (isNaN(id)) { return NextResponse.json( { error: "Brand ID must be a number" }, { status: 400 } ); } const discs = await prisma.disc.findMany({ where: { brandId: id, }, }); return NextResponse.json(discs); }
After a few rebuild and restarts, it seems to not always be happening on this given code.
EDIT: Also happen when I used the Prisma adapter to next-auth and tried to use
/api/auth/signinEDIT: I used generated client, and have switched to following Turorepos example, and have not had the same problems again in dev. Before the switch, I ran my app in build-mode, and did not experience this error in local build-run.
see #19564 (comment) / got here while trying to run prisma+sveltekit on fly.io
I got here from a Serverless project using
serverless-plugin-esbuild. I think the documentation at https://www.prisma.io/docs/concepts/components/prisma-client/module-bundlers could use some expansion. I'm using esbuild here and I found some of the references to manual builder settings (e.g. webpack) a bit misleading in this case. With the serverless framework all you need is something like:package: { individually: true, patterns: [ '!node_modules/.prisma/client/libquery_engine-*', '!node_modules/@prisma/engines/**', 'node_modules/.prisma/client/schema.prisma', // 'node_modules/.prisma/client/libquery_engine-rhel-*', ], },Other sections of the document have examples that led me to the above.
Reacted by DoHyeong LeeI got here from a Serverless project using
serverless-plugin-esbuild. I think the documentation at https://www.prisma.io/docs/concepts/components/prisma-client/module-bundlers could use some expansion. I'm using esbuild here and I found some of the references to manual builder settings (e.g. webpack) a bit misleading in this case. With the serverless framework all you need is something like:package: { individually: true, patterns: [ '!node_modules/.prisma/client/libquery_engine-*', '!node_modules/@prisma/engines/**', 'node_modules/.prisma/client/schema.prisma', // 'node_modules/.prisma/client/libquery_engine-rhel-*', ], },Other sections of the document have examples that led me to the above.
I just solved the same problem by following this solution. Thank you for sharing.
Do you mean
serverless-esbuild? can i see the full example of your serverless.yaml(ts) file, thanks ( also having the same issue)Im in the same spot using serverless-esbuild. Where did you put this?
package: { individually: true, patterns: [ '!node_modules/.prisma/client/libquery_engine-*', '!node_modules/@prisma/engines/**', 'node_modules/.prisma/client/schema.prisma', // 'node_modules/.prisma/client/libquery_engine-rhel-*', ], },@wmlutz At the top level of the serverless config, e.g.
... frameworkVersion: '3', package: { individually: true, patterns: [ '!node_modules/.prisma/client/libquery_engine-*', '!node_modules/@prisma/engines/**', 'node_modules/.prisma/client/schema.prisma', // 'node_modules/.prisma/client/libquery_engine-rhel-*', ], }, provider: { ...Note that this example is for the JS/TS version of it (
serverless.ts) but it's the same thing forserverless.ymlif you're using that, you just need to convert the above from JS to YML.Reacted by Will LutzI've only ever seen serverless.yml - so it took my brain a minute to figure it out crrobinson14, but I got it. And it's working! Thanks.
@crrobinson14 That you for the helpful comments. I continue to have the same issue where my deployed lambda is unable to find the schema.prisma. My structure is as follows:
app - apps - serverless-func - serverless.ts - src - functions - node_modules (Does not contain the prisma schema) - packages - db - prisma - schema.prisma - node_modules (Contains the prisma schema)I am able to build and the deploy the function that imports the db code from the package managed by Turborepo. However, when the js runs, it errors out with the unable to find schema.prisma error. Any help would be greatly appreciated. Happy to open source my repo current repo as well.
@aneurycasado You need to manually bundle the schema.prisma file. Since you have a monorepo and it's in a different directory Serverless is probably having trouble finding it. Maybe try adding a manual copy step to copy that file? The patterns block above is relative to the serverless folder, in your case
apps/serverless-func. So if you wanted this to work in a monorepo as I'm doing above, you'd need to copynode_modules/.prisma(the generated Prisma client) into yourserverless-func/node_modulesfolder before running Serverless builds. Or possibly symlink it or something...Thank you for the reply. I greatly appreciate it. I feel like I must be missing something with turborepo or the serverless build step. For now, I can probably create a bash script that moves this .prisma folder into the serverless app node modules folder.
Which package manager are you using?
Package manager: npm
Version: 8.19.4Is your workspace a monorepo setup?
YesIs a bundler in use? If yes, which one?
webpackIs a framework in use? If yes, which one?
nodejs 14.xYour project uses TypeScript or just JavaScript?
JavaScript
When you saw our message, did it happen locally or in deployment?
both
Where is your project deployed?
Not deployed yet
How can we reproduce this?
Download this project here
and follow this link and follow thewebpackimplementationDeployment with serverless-webpackWhat error exactly are you getting?
ERROR PrismaClientInitializationError: Prisma Client could not find its `schema.prisma`. This is likely caused by a bundling step, which leads to `schema.prisma` not being copied near the resulting bundle. We would appreciate if you could take the time to share some information with us. Please help us by answering a few questions: https://pris.ly/bundler-investigation-error at new _t (/var/task/index.js:24649:127) at t.getEngine (/var/task/index.js:27965:20) at new t (/var/task/index.js:27947:1406) at build/chunks/db.js (/var/task/index.js:28363:14) at __init (/var/task/index.js:9:59) at build/entries/endpoints/api/validate/_server.ts.js (/var/task/index.js:39616:5) at __init (/var/task/index.js:9:59) at /var/task/index.js:43462:55 at async respond (/var/task/index.js:43160:22) at async Runtime.handler (/var/task/index.js:43513:20) { clientVersion: '5.0.0', errorCode: undefined }This is from a sveltekit project that uses this adapter. The error above is from the lambda function that it deploys to AWS. We are migrating this project from knex (where these routes worked) to prisma.
Which package manager are you using?
pnpm@8.6.1
Is your workspace a monorepo setup?
No, it's a standard sveltekit project layout
Is a bundler in use? If yes, which one?
vite@4.3.9
Is a framework in use? If yes, which one?
sveltekit@1.20.4
Your project uses TypeScript or just JavaScript?
TS@4.9.5
When you saw our message, did it happen locally or in deployment?
When running local via 'pnpm run dev' the issue does not occur. When running local via 'pnpm run preview' the error message does not print, but all routes using prisma return a 403 error - no message is given in the console.
When deployed to AWS viapnpm run buildthe above error message is returned.Where is your project deployed?
AWS via a cloudfront + s3 + api gateway + lambda configuration.
How can we reproduce this?
I will try and put together a reproduction repo tomorrow, but I suspect all you'd need to do is use sveltekit + prisma in preview.
I ran into this same error
"PrismaClientInitializationError: Prisma Client could not find itsschema.prisma. This is likely caused by a bundling step, which leads toschema.prismanot being copied near the resulting bundle. We would appreciate if you could take the time to share some information with us."after migrating from prisma 4 to 5.My project uses Webpack
5.87.0to copy the Prisma binary and schema file into a zipped bundle for AWS Lambda.My
distfolder for AWS Lambda looked like this on Prisma 4:main.js node_modules/ .prisma/ client/ libquery_engine-linux-arm64-openssl-1.0.x.so.node schema.prismaI had to update it to this to fix the error:
main.js libquery_engine-linux-arm64-openssl-1.0.x.so.node schema.prismaHas there been a change in the path prisma looks for the schema and binary in the upgrade from 4 -> 5? It might be worth adding that to the upgrade docs if so
- locked and limited conversation to collaborators
on Jul 17, 2023
Hi, you have been directed to this issue because we want to learn more about your project setup. Thanks to your answers, we will be able to better take design decisions in the future.
We'd appreciate if you could take 5 minutes to answer a few questions for us. You can write your reply directly in this issue as a comment. Copy paste these questions in your answer, leave the answer blank if you don't know.
What error exactly are you getting?
Please share the error you are getting, and when exactly.
Which package manager are you using?
For instance
npm,pnpm, oryarn. Please attach the version if you know it.Is your workspace a monorepo setup?
Is your setup hosting multiple packages in a single workspace?
Is a bundler in use? If yes, which one?
Are you using
webpack,swc,esbuild,rollup, or any other bundler?Is a framework in use? If yes, which one?
Are you using
Next.js,Next, or any other framework?Your project uses TypeScript or just JavaScript?
Do you prefer using TypeScript or JavaScript within your project, or both?
When you saw our message, did it happen locally or in deployment?
The message was "Please help us by answering a few questions".
Where is your project deployed?
Are you deploying to Vercel, Netlify, Lambda, or something else?
How can we reproduce this?
Could you please provide us with some code to reproduce this?