graphql-nexus/nexus-prisma

Cannot find module @prisma/client in Vercel deployment

skittlesaur opened this issue · 8 comments

I tried deploying a dummy application to vercel using graphql-yoga and nexus-prisma and i keep getting this runtime error on vercel.

Cannot find module '/vercel/path0/node_modules/@prisma/client'
Require stack:
- /var/task/apps/graphql/node_modules/.nexus-prisma/index.js
- /var/task/apps/graphql/node_modules/nexus-prisma/dist-cjs/entrypoints/main.js
- /var/task/apps/graphql/src/types/user.js
- /var/task/apps/graphql/src/queries.js
- /var/task/apps/graphql/src/utils/schema.js
- /var/task/apps/graphql/src/utils/yoga.js
- /var/task/apps/graphql/src/index.js
Did you forget to add it to "dependencies" in `package.json`?
RequestId: 9a9af12a-0496-468a-925d-d70e72c7710a Error: Runtime exited with error: exit status 1
Runtime.ExitError

My types/user.ts file is just a copy from the documentation and looks like this:

import { objectType } from 'nexus'
import { User } from 'nexus-prisma'

const UserType = objectType({
  name: User.$name,
  definition(t) {
    t.field(User.id)
    t.field(User.email)
    t.field(User.name)
    t.field(User.createdAt)
  },
})

export default UserType

Some info in package.json that might be relevant:

{
  "name": "graphql",
  "version": "1.0.0",
  "main": "src/index.ts",
  "scripts": {
    "build": "sucrase ./src -d ./dist --transforms typescript,imports",
    "start": "node dist/index.js",
    "postinstall": "prisma generate"
  },
  "dependencies": {
    "@prisma/client": "^4.13.0",
    "graphql": "^16.6.0",
    "graphql-yoga": "^3.9.1",
    "nexus": "^1.3.0",
    "nexus-prisma": "^1.0.5",
    "prisma": "^4.13.0",
  },
}

note: i'm using yarn since i found previous issues similar to this with pnpm but it's not really my issue here

@skittlesaur for some reason prisma generator returns location of @prisma/client in /vercel/path0/node_modules/@prisma/client instead of /var/task/apps/graphql/node_modules/@prisma/client. Can you share the whole setup?

This is the concerning logic

* Get the appropriate import ID for Prisma Client.

@skittlesaur for some reason prisma generator returns location of @prisma/client in /vercel/path0/node_modules/@prisma/client instead of /var/task/apps/graphql/node_modules/@prisma/client. Can you share the whole setup?

sure, it's just a template im setting up for my future projects so it barely has any code. here's the link to the repo
https://github.com/skittlesaur/my-turbo-template

the graphql project im trying to deploy is located in apps/graphql

@skittlesaur for some reason prisma generator returns location of @prisma/client in /vercel/path0/node_modules/@prisma/client instead of /var/task/apps/graphql/node_modules/@prisma/client. Can you share the whole setup?

sure, it's just a template im setting up for my future projects so it barely has any code. here's the link to the repo https://github.com/skittlesaur/my-turbo-template

the graphql project im trying to deploy is located in apps/graphql

Can you somehow get the information where is the real location of @prisma/client once deployed to vercel ?

I'm not really sure how i can do that. however, in the build logs has the following lines of prisma client generation and nexus if that's helpful

✔ Generated Prisma Client (4.13.0 \| library) to ./../../node_modules/@prisma/client in 50ms
19:43:57.941

✔ Generated Nexus Prisma to ./node_modules/.nexus-prisma in 10ms
19:43:57.942

try to set prismaClientImportId: '@prisma/client' or prismaClientImportId: '../../node_modules/@prisma/client' by custom settings file https://graphql-nexus.github.io/nexus-prisma/docs/settings/gentime

Setting it to prismaClientImportId: '@prisma/client' works now :D

I'm quite curious what was actually happening and how did that fix it because i been looking for an answer to this for a couple of days now and delaying my uni projects

And thank you so much for the help! :D

I'm not familiar with the Vercel internals in relation to your setup. But the problem is that package @prisma/client is not in the same place when generate was called (build phase) as in runtime. It could be related to your mono repo with your build tooling.