Skip to content

User questions: Bundler error #19351

Description

@millsp

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, or yarn. 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?

Activity

  1. kongebra commented on Jun 2, 2023

    @kongebra

    Which package manager are you using?

    Package manager: pnpm
    Version: 8.5.1

    Is your workspace a monorepo setup?

    Monorepo with turborepo

    Is 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.4

    Your 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.ts in the new App-router from Next.js

    type 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/signin

    EDIT: 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.

  2. gaarf commented on Jun 12, 2023

    @gaarf

    see #19564 (comment) / got here while trying to run prisma+sveltekit on fly.io

  3. crrobinson14 commented on Jun 21, 2023

    @crrobinson14

    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.

  4. shine1594 commented on Jun 21, 2023

    @shine1594

    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.

    I just solved the same problem by following this solution. Thank you for sharing.

  5. kaykhan commented on Jun 23, 2023

    @kaykhan

    Do you mean serverless-esbuild? can i see the full example of your serverless.yaml(ts) file, thanks ( also having the same issue)

  6. wmlutz commented on Jun 29, 2023

    @wmlutz

    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-*',
        ],
      },
    
  7. crrobinson14 commented on Jun 29, 2023

    @crrobinson14

    @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 for serverless.yml if you're using that, you just need to convert the above from JS to YML.

  8. wmlutz commented on Jun 29, 2023

    @wmlutz

    I'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.

  9. aneurycasado commented on Jul 7, 2023

    @aneurycasado

    @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.

  10. crrobinson14 commented on Jul 7, 2023

    @crrobinson14

    @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 copy node_modules/.prisma (the generated Prisma client) into your serverless-func/node_modules folder before running Serverless builds. Or possibly symlink it or something...

  11. aneurycasado commented on Jul 8, 2023

    @aneurycasado

    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.

  12. ssalihu commented on Jul 8, 2023

    @ssalihu

    Which package manager are you using?

    Package manager: npm
    Version: 8.19.4

    Is your workspace a monorepo setup?
    Yes

    Is a bundler in use? If yes, which one?
    webpack

    Is a framework in use? If yes, which one?
    nodejs 14.x

    Your 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 the webpack implementation Deployment with serverless-webpack

  13. k-dahl commented on Jul 13, 2023

    @k-dahl

    What 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 via pnpm run build the 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.

  14. adamjq commented on Jul 16, 2023

    @adamjq

    I ran into this same 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." after migrating from prisma 4 to 5.

    My project uses Webpack 5.87.0 to copy the Prisma binary and schema file into a zipped bundle for AWS Lambda.

    My dist folder 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.prisma
    

    I had to update it to this to fix the error:

    main.js
    libquery_engine-linux-arm64-openssl-1.0.x.so.node
    schema.prisma
    

    Has 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

  15. locked and limited conversation to collaborators on Jul 17, 2023
  16. converted this issue into a discussion #20257 on Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions