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'
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)
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 (so I just didn’t try zisi)
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.
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.
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.
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.
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.
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.
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!