Home
Support Forums

Can't find '@prisma/client' after deploying, but it works on dev

Hey there!
My sitename is zen-noether-5d2aae

I’m getting some trouble while trying to work on netlify with:

  • apollo-server-lambda
  • prisma
  • nexus-prisma-plugin

I’ve managed to get this to work on netlify dev locally, and also to build it online.
But when I try to fetch .../.netlify/functions/graphql I get
Error: Cannot find module '@prisma/client'

netlify.toml

[functions]
    external_node_modules = ["@kenchi/nexus-plugin-prisma", "@prisma/client", "nexus-plugin-prisma"]
[build]
  command = "npm install -g pnpm && pnpm -w shared install && pnpm -w backend install && pnpm build"
  functions = "src/lambda" #  netlify-lambda reads this
  ignore = "if [ $CACHED_COMMIT_REF != $COMMIT_REF ]; then git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF . ../shared; fi"
[build.environment]
    NPM_FLAGS="--prefix=/dev/null"
    NODE_VERSION='14'

I use pnpm monorepo too:
Here is my pseudo-folder-structure

. Root  (but not the monorepo root)
    netlify.toml
+---.netlify
|   +---functions
|   +---functions-serve
+---src
|   +---lambda
|   +---functionsThatAreUsedInLambda

If there is some more specific things I could provide to help someone help me, please ask! I just don’t want to bloat with useless info (and I don’t really know how yet to create a reproduction repository of something that needs a minimal database to interact with prisma yet)

Thanks in advance!

seems to be related

Hi @outerlook,

Are you facing the same issue when using esbuild instead of zisi?

I use typescript in my code, so I think it is automatically esbuild which builds, right? Yes, I also tried putting ‘esbuild’ as builder and I get the same error :confused: (so I just didn’t try zisi)

Could you try adding AWS_LAMBDA_JS_RUNTIME environment variable with the value nodejs14.x?

is it ok to ad to netlify.toml, or should I add to netlify UI?

It will go in the UI.

Still not working :confused:

same thing, built successfully, but the same error when I try to fetch the function.

part which says it was correctly generated

10:02:39 AM: ✔ Generated Prisma Client (2.30.2) to ./../node_modules/.pnpm/@prisma+client@2.30.2_prisma@2.30.2/node_modules/@prisma/client in 1.14s
10:02:39 AM: You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client
10:02:39 AM: ```
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()

I don’t know where to find output in the build log that shows this variable was correctly set whith successful builds. But I did set it up at UI.

Just to test, would it be possible for you to create a minimal reproduction when using npm? Not saying it’s a pnpm issue, but we might have to eliminate some variables here.

You can logs the environment variables, but you need not do it. I checked from our end and it appears that the variable has been correctly set.

Well, as it seems to be the really same error as Error: Cannot find module '@prisma/client' in netlify functions when using prisma + next + rushjs + pnpm · Issue #636 · netlify/zip-it-and-ship-it · GitHub, may we use the repro the issue author provided? GitHub - abereghici/prisma-next-netlify-rush

And as he said, it seems to corrrectly vanish on npm usage

Oh, alright, this repro uses rush + pnpm and you are asking for npm

So, in meantime, I need this to work with pnpm either way. It isn’t compatible yet for some reason with pnpm monorepos?

Can you explain why just including to external_node_modules won’t do the job?

I’m having multiple endless problems about dependecies.

I have a couple questions if you can to help me debugging it…

May I depend on things outside lambda own folder? It wouldn’t break these things I’m asking about?
for example:

project root/
├─ backend/   -> this is the root for netlify UI
│  ├─ netlify.toml
│  ├─ package.json
│  ├─ src/
│  │  ├─ lambdas/
│  │  │  ├─ graphql.ts
│  │  │  ├─ otherLambda.ts
│  │  ├─ sharedFunctions/

As suggested by the github issue’s author, I’ve included prisma-engine-versions to package.json then it started working. But next problem arises, prisma nexus isn’t found.

I tried things like:
add the pnpm option --shamefully-hoist on install, no success
add node_modules/nexus/** to included_files option on .toml, but then each dependencies of nexus are not bundled together, then triggers missing module error for them (it seems not the right solution)

Please, if you may answer any of these questions by the time you can, or share some meantime workaround, it would be enormously helpful. I’d really like to use netlify within my project, but these has been big blockers for me. :confused:

I almost created another minimal repro without rush that self contains a SQLite file as database to test.

But I didn’t get it to work on Netlify, just locally.
(the problem here is I don’t know how to preserve the file for prisma to be able to read)

Anyway, the structure is the same as I get errors, if someone can give any idea to create this self-contained repro that works on netlify online. Or if this is already enough for the team to reproduce the error with a Database of your own online.

FYI, this should work locally, but fail online

outerlook/netlify-prisma-nexus

Hi @outerlook,

Sorry for the delay here. While I don’t have answers to most of your questions, I’m trying to loop in someone from the devs who can probably share some insights on what might be happening. Thank you for the patience.

Thanks, @hrishikesh !

I’m trying to get better understanding of lambda’s side of the problem with cdk. I understand a little bit more of the problem now, but I don’t know yet how to make it work with netlify without an option like afterBundling option to overcome some of these issues I’m getting.

For example, I know there are some packages in prisma that requires generate after bundling (if not copying like zip-it-and-ship-it does right now), there are other cases like nexus-plugin-prisma that requires nexus to be installed under node_modules just as a check (could be an empty module, but the real one bundled)…

Is there a good way to customize options like afterBundling, afterInstalling, beforeBundling to overcome this issues while still leveraging the simplicity of netlify ease of deploying? (directly from typescript, etc)

Sorry if it is a little bit in another direction, but any solution you may come up with, would be helpful. :slight_smile:

One of the devs believes that it might be related to zip-it-ship-it, however we’d like to wait for confirmation by our expert in that topic. Sadly, they’re out till next Monday. By any chance, could this wait till they can take a look?

At the moment, that’s sadly not the case. But it’s a great idea for a feature request.

Alright. Let’s put this aside until next monday then.

Perfect! We’ll poke our team internally to ensure that we get eyes on it as early as possible next week. The team will likely follow up in the issue directly but we will follow up here otherwise!

2 Likes