#Cannot find module '.prisma/client/default'

4 messages · Page 1 of 1 (latest)

hearty saddleBOT
#

You've gone full bot mode! Let me fetch that AI answer for you ASAP.

hearty saddleBOT
# hearty saddle You've gone full bot mode! Let me fetch that AI answer for you ASAP.

The error Cannot find module '.prisma/client/default' when using pnpm in a Docker container is a known issue related to how pnpm handles node_modules structure and postinstall hooks, which are responsible for running prisma generate. Here are the key points and solutions based on your setup and the knowledge sources:

  1. pnpm and Prisma Client Generation: pnpm does not always run postinstall hooks, especially in recent versions, so prisma generate may not be triggered automatically. This results in the .prisma/client directory not being created, leading to the error you see at runtime. The recommended solution is to always run prisma generate explicitly in your Dockerfile or CI pipeline, which you are already doing. However, with pnpm, the generated files may not be in the expected location or may not be copied into the final image as needed Prisma Client is not generated into the node_modules/.prisma/client folder by default when using pnpm.

  2. Copying node_modules/.prisma: With pnpm, the .prisma directory may be nested inside .pnpm and not directly under node_modules. This can cause issues when copying or referencing the generated client. You may need to explicitly copy the .prisma directory from the build context to the runtime image, for example:

    COPY --from=build /usr/src/app/node_modules/.prisma /usr/src/app/node_modules/.prisma
    

    This is especially important if you use multi-stage builds or copy only specific files into the final image Error: Cannot find module '.prisma/client/sql'.

  3. pnpm v10+ and postinstall: If you are using pnpm v10 or later, you must approve postinstall scripts for certain packages. Add this to your package.json:

    "pnpm": {
      "onlyBuiltDependencies": [
        "@prisma/client"
      ]
    }
    

    Or run pnpm approve-builds [Cannot find module '.prisma/client/def

hearty saddleBOT
# hearty saddle You've gone full bot mode! Let me fetch that AI answer for you ASAP.

ault' when using custom output with pnpm](https://github.com/prisma/prisma/issues/25833).

  1. General Advice: If you are using a custom output path for the Prisma client, ensure your import paths match the generated location. Avoid generating Prisma Client into node_modules subfolders manually, as this can cause further issues with pnpm Prisma Client is not generated into the node_modules/.prisma/client folder by default when using pnpm.

Summary:

  • Always run prisma generate explicitly in your Dockerfile.
  • Ensure the generated .prisma directory is present in the final image.
  • For pnpm v10+, approve postinstall scripts.
  • Double-check your import paths if using custom output.

If you follow these steps and still encounter issues, please check the exact location of the generated Prisma client and ensure it is available at runtime in your container.

viral summit
#

It was a misconfiguration from my end. I missed out on copying the schema.prisma file in the dockerfile file. Solved!
Thank you @hearty saddle for being my rubber ducky 🙂