0

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

dennis
  • 765
  • 1
  • 11
  • 25
  • Possible duplicate of [npm install won't install devDependencies](http://stackoverflow.com/questions/34700610/npm-install-wont-install-devdependencies) – gnerkus Feb 08 '16 at 19:06
  • I think you have it backwards npm install will install all dependencies. – Robert Moskal Feb 08 '16 at 19:24
  • I edited my answer and tried to give more context, it's not about installing from the shell like in the linked question. – dennis Feb 09 '16 at 05:06

0 Answers0