9

I'm confused about how Prisma code generation in production works. The Prisma CLI is supposed to be installed in devDependencies, yet the npx prisma generate command needs to be available in production, since the generated code is necessary for the application. How can I resolve this? I tried running npm i --production and npx prisma generate, which led to the expected problem of npx trying to auto-install prisma and getting Prisma 1 instead of Prisma 2 and then expecting a prisma.yml file which doesn't exist.

Robert Moore
  • 2,207
  • 4
  • 22
  • 41

3 Answers3

2

There's no need to run the prisma generate command that is executed on installation of the @prisma/client.

EDIT: https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/generating-prisma-client

Centux
  • 29
  • 1
  • 1
    But running the `prisma generate` command, done automatically or manually, would require the Prisma CLI to be installed. – Robert Moore Sep 20 '20 at 14:35
0

Prisma has various guides for installing on different environments. For example, this one talks about installing on vercel.

https://www.prisma.io/docs/guides/deployment/deployment-guides/deploying-to-vercel

Postinstall hook The package.json uses the postinstall hook script to run prisma generate. Typically this would go in the build step. Because Vercel caches node_modules after the dependencies are installed, the functions won't have access to the generated Prisma Client.

Generating the Prisma Client in postinstall ensures that the generated Prisma Client in node_modules/@prisma/client is available to the functions.

yuvalhazaz
  • 80
  • 2
0

That's what I did in package.json file (It was a deploy a Next app on Versel) I just added generate command to the build script:

"scripts": {
    "dev": "next dev",
    "build": "prisma generate && next build",
    "start": "next start",
    "lint": "next lint"
  },

Not sure if it is a correct way, though..

maxuapro
  • 1
  • 1