question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Cannot find module '@prisma/client' in netlify functions when using prisma + next + rushjs + pnpm

See original GitHub issue

- Do you want to request a feature or report a bug?

🐞

- What is the current behavior?

In a rush monorepo with pnpm @prisma/client and .prisma files aren’t included in function node_modules and throw the error:

{
errorType: "Runtime.ImportModuleError",
errorMessage: "Error: Cannot find module '@prisma/client' Require stack: - /var/task/.netlify/functions-internal/next_api_views/next_api_views.js - /var/task/next_api_views.js - /var/runtime/UserFunction.js - /var/runtime/index.js",
trace: [
"Runtime.ImportModuleError: Error: Cannot find module '@prisma/client'",
"Require stack:",
"- /var/task/.netlify/functions-internal/next_api_views/next_api_views.js",
"- /var/task/next_api_views.js",
"- /var/runtime/UserFunction.js",
"- /var/runtime/index.js",
" at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
" at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
" at Object.<anonymous> (/var/runtime/index.js:43:30)",
" at Module._compile (internal/modules/cjs/loader.js:999:30)",
" at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)",
" at Module.load (internal/modules/cjs/loader.js:863:32)",
" at Function.Module._load (internal/modules/cjs/loader.js:708:14)",
" at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)",
" at internal/main/run_main_module.js:17:47"
]
}

- If the current behavior is a bug, please provide the steps to reproduce.

  • Create a rush monorepo with pnpm as package manager.
  • Add a nextjs app with prisma inside of monorepo
  • Set next target to experimental-serverless-trace
  • Run prisma generate && netlify-cli build && netlify-cli deploy
  • Unzip a function that uses prisma from .netlify/functions/ and see that @prisma/client and .prisma are not included in node_modules

If you change the package manager from pnpm to npm then is working as expected.

I created a repository where you can reproduce the issue: https://github.com/abereghici/prisma-next-netlify-rush

- What is the expected behavior? @prisma/client and .prisma files should be included in node_modules when using pnpm.

- Please mention your node.js, and operating system version.

System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 372.44 MB / 32.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.17.2 - /usr/local/bin/node
    Yarn: 1.22.0 - /usr/local/bin/yarn
    npm: 6.14.13 - /usr/local/bin/npm

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
netlify-team-account-1commented, Sep 16, 2021

Thank you @abereghici! I think I was able to reproduce the error based on https://github.com/outerlook/netlify-prisma-nexus, I’ll use your repository to verify a fix once we have it.

1reaction
outerlookcommented, Sep 1, 2021

Yay, sorry but happy to see this issue. I’m getting this too.

If I may add, local netlify dev works perfectly. Only when uploading, the problem arises. In my case, if I try to add --shamefully-hoist to install option, the error displayed complains about lack of nexus-plugin-prisma module.

But while using pnpm monorepo, it ain’t so easy to go back to npm structure

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't find '@prisma/client' after deploying, but it works on dev
Error : Cannot find module '@prisma/client' in netlify functions when using prisma + next + rushjs + pnpm. opened 05:22PM - 31 Aug...
Read more >
2 - Stack Overflow
The solution provided by Mojtaba Barari works but it results in @prisma packages being present in both resources/app/node_modules and ...
Read more >
Runtime importmoduleerror error cannot find module handler
Error : Cannot find module '@prisma/client' in netlify functions when using prisma + next + rushjs exports. Modules are performed during import, ...
Read more >
Netlify deployment error: Cannot find module
The Netlify deploy is configured to build and deploy functions via Netlify Lambdas, which does not include static files. You can emulate the ......
Read more >
Syntax - Tasty Web Development Treats - Podcast Addict
45:58 Query your data with Prisma client 49:43 Have you looked into ... 50:58 Sick Picks Netlify announcing serverless compute with edge functions...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found