Prisma-client-js: `postinstall` script of this package fails if using env var in my schema

Created on 12 Dec 2019  ยท  5Comments  ยท  Source: prisma/prisma-client-js

This package contains a postinstall script to perform the photon package generation.

I am leveraging an environment variable for my db connection string. Unless I make this env var available before running npm install the postinstall of this package will fall over.

See example output:

โฏ npm install
npm WARN rm not removing /prisma2-pg-jest/node_modules/.bin/semver as it wasn't installed by /prisma2-pg-jest/node_modules/semver
npm WARN rm not removing /prisma2-pg-jest/node_modules/fsevents/node_modules/.bin/node-pre-gyp as it wasn't installed by /prisma2-pg-jest/node_modules/fsevents/node_modules/node-pre-gyp

> [email protected] install /prisma2-pg-jest/node_modules/fsevents
> node install

node-pre-gyp WARN Using request for node-pre-gyp https download
[fsevents] Success: "/prisma2-pg-jest/node_modules/fsevents/lib/binding/Release/node-v72-darwin-x64/fse.node" is installed via remote

> [email protected] install /prisma2-pg-jest/node_modules/prisma2
> node download-build/index.js || echo "Have fun with prisma2!"

> Downloading Prisma engines for darwin [====================] 100%


> @prisma/[email protected] postinstall /prisma2-pg-jest/node_modules/@prisma/photon
> node scripts/generate.js

Error: Schema parsing
error: Environment variable not found: POSTGRES_URL.
  -->  schema.prisma:7
   |
 6 |   provider = "postgresql"
 7 |   url      = env("POSTGRES_URL")
 8 | }
   |

added 40 packages from 15 contributors, removed 77 packages, updated 530 packages and audited 886740 packages in 16.184s
found 0 vulnerabilities

To be clear, I don't have any postinstall defined in my project. It appears to be explicitly executing the one defined within @prisma/photon

I'd personally prefer to explicitly call the prisma2 generate myself, either manually, or in mine own postinstall script.

bu2-confirmed kinbug env

Most helpful comment

@pantharshit00 https://github.com/prisma/photonjs/issues/326 was closed prematurely.

  • The error isn't a result of a missing environment variable
  • POSTGRES_URL _does_ exist in a .env file
  • prisma _does_ recognize it when you run prisma2 generate

The postinstall command - which automatically runs when you run npm install - is the cause of the error. The original log provided here by @ctrlplusb illustrates that: https://github.com/prisma/photonjs/issues/326#issue-537085896

And the screenshot I provided here shows how prisma2 generate works as expected immediately after getting the error triggered by postinstall calling node scripts/generate.js

All 5 comments

I've had the same issue.

To add to that, it's consistently using the old @prisma/photon version (preview 018.2) for me as well, even though I'm on the latest version (alpha.451)

Screen Shot 2019-12-12 at 4 32 26 PM

Screen Shot 2019-12-12 at 4 37 37 PM

Is it possible this is NPM specific?


Terminal screenshots from both npm install & yarn install

Screen Shot 2019-12-13 at 11 42 25 AM
Screen Shot 2019-12-13 at 11 42 31 AM
Screen Shot 2019-12-13 at 11 42 50 AM

We are aware that currently environment variables are required to be present if you define them in your schema. We have an open issue about this: https://github.com/prisma/prisma2/issues/800

In the meanwhile, you can just create .env file with empty envs as a workaround.

@pantharshit00 https://github.com/prisma/photonjs/issues/326 was closed prematurely.

  • The error isn't a result of a missing environment variable
  • POSTGRES_URL _does_ exist in a .env file
  • prisma _does_ recognize it when you run prisma2 generate

The postinstall command - which automatically runs when you run npm install - is the cause of the error. The original log provided here by @ctrlplusb illustrates that: https://github.com/prisma/photonjs/issues/326#issue-537085896

And the screenshot I provided here shows how prisma2 generate works as expected immediately after getting the error triggered by postinstall calling node scripts/generate.js

Thanks for reporting!

Before tackling this, we need to create a spec on how to handle env vars in Prisma in general.

Related: https://github.com/prisma/prisma2/issues/1255

Was this page helpful?
0 / 5 - 0 ratings

Related issues

samrith-s picture samrith-s  ยท  3Comments

divyenduz picture divyenduz  ยท  3Comments

Errorname picture Errorname  ยท  3Comments

AhmedElywa picture AhmedElywa  ยท  4Comments

macrozone picture macrozone  ยท  4Comments