I'm trying to call npm install
from an npm script, but the devDependencies won't install even if I set the NODE_ENV
to development
like that:
{
"name": "test",
"version": "1.0.0",
"private": true,
"scripts": {
"deploy": "NODE_ENV=development npm i"
},
"devDependencies": {
...
}
}
This way, only the dependencies are installed when running npm run deploy
, not the devDependencies.
Is this by design?
To give a bit more information, the NODE_ENV
on the machine is set to production
and should stay that way. I want to set the environment variable just for one script line and that normally works for other scripts. The line sets the NODE_ENV
correctly and the installer runs, but it's not taking the environment variable into account - calling npm install
from a script seems to run always as if the --production
flag is set.
So, running the line NODE_ENV=development npm i
from the shell installs devDependencies and dependencies (it overwrites the NODE_ENV variable which is set on the machine, just for this one command), but running the same line in an package.json scripts block ignores the NODE_ENV overwriting.
- The
--production
flag doesn't help, because I also want to install the devDependencies. - The
--only[prod|dev]
also doesn't do what I want, because it only installs either only dev or only prod dependencies if I read that right.
The following line in the package.json
correctly prints development
as the environment variable, even if production
is set on the machine:
"scripts": {
"envTest": "NODE_ENV=development node -e 'console.log(process.env.NODE_ENV);'"
}
Thanks