Eric Xin Zhang
Eric Xin Zhang

Reputation: 1349

How to specify an environment variable before npm install in package.json?

Situation

Within the company we've got our own NPM registry and the corporate network blocks the access to the public NPM registry.

Problem

To install cypress, we would like the binary to be downloaded from our own NPM registry by running following command:

export CYPRESS_INSTALL_BINARY=<Our NPM registry URL>

However it does not work if we add the above command into the preinstall hook. We believe it's because NPM runs each task in a separate process.

So my question is, how to export an environment variable for npm install to use in package.json?

Upvotes: 0

Views: 1015

Answers (1)

bbortt
bbortt

Reputation: 405

Just add a line to the .npmrc file like this:

CYPRESS_INSTALL_BINARY = https://some.registry

Which ends up in Cypress resolving the donwload from the URL specified.

[08:47:39]  Downloading Cypress     [started]
[08:47:39]  Downloading Cypress     [failed]
[08:47:39] → The Cypress App could not be downloaded.

Please check network connectivity and try again:

----------

URL: https://some.registry
Error: unable to reach host

----------

Upvotes: 0

Related Questions