npm-run-all
npm-run-all copied to clipboard
Doesn't work with cross-env
{
"scripts": {
"set-env:test": "cross-env NODE_ENV=test",
"set-env:staging": "cross-env NODE_ENV=staging",
"set-env:production": "cross-env NODE_ENV=production",
"deploy:managers": "node ./deployment-scripts/deploy-managers",
"deploy:managers:test": "npm-run-all set-env:test deploy:managers"
}
}
When I run deploy:managers:test
script I expect the NODE_ENV
variable to be set to test
for the ./deployment-scripts/deploy-managers.js
script. But NODE_ENV
is undefined
.
If I run the cross-env NODE_ENV=test deploy:managers
command then it works as expected.
Is it a bug in npm-run-all
or is it me doing something wrong?
These are two solutions using cross-env-shell
which is part of cross-env
"env:prod": "cross-env-shell NODE_ENV=production",
"build:a": "cross-env-shell npm run env:prod npm-run-all a b c"
// or
"build:b": "cross-env-shell NODE_ENV=production npm-run-all a b c"
@jagretz Thanks, I'll check it out.
The problem here isn't cross-env
but the fact that variables aren't shared across tasks
{
"set": "HI=hello",
"use": "echo $HI stranger"
}
$ npm-run-all set use
stranger
To fix this, you have to set the variable before npm-run-all
, if possible. For example:
$ HI=hello npm-run-all use
hello stranger
Or in your case
{
"deploy:managers:test": "cross-env NODE_ENV=test npm run deploy:managers"
}