#Cannot find module '.prisma/client/default'
4 messages · Page 1 of 1 (latest)
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:
-
pnpm and Prisma Client Generation: pnpm does not always run postinstall hooks, especially in recent versions, so
prisma generatemay not be triggered automatically. This results in the.prisma/clientdirectory not being created, leading to the error you see at runtime. The recommended solution is to always runprisma generateexplicitly 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. -
Copying node_modules/.prisma: With pnpm, the
.prismadirectory may be nested inside.pnpmand not directly undernode_modules. This can cause issues when copying or referencing the generated client. You may need to explicitly copy the.prismadirectory from the build context to the runtime image, for example:COPY --from=build /usr/src/app/node_modules/.prisma /usr/src/app/node_modules/.prismaThis 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'.
-
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
ault' when using custom output with pnpm](https://github.com/prisma/prisma/issues/25833).
- 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_modulessubfolders 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 generateexplicitly in your Dockerfile. - Ensure the generated
.prismadirectory 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.
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 🙂