npm install --save-dev doesn't install package at all

(David Luzar) #1

Today, all of a sudden, installing a package as dev dependency (e.g. npm i -D react) doesn’t install it into node_modules, and only adds it to devDependencies in package.json.

Then, I have to do npm i --only=dev for npm to actually install the package.

On top of it, if the package is already installed as devDep, installing a different version using npm i -D package@version displays a message that the package is up to date, and I have to install the different version as a non-dev dependency again.

Also, doing a clean install/update via npm install only installs non-dev dependencies, and again I have to do an extra npm i --only=dev to get the dev deps.

Any idea what’s going on?

What I’ve tried:

  • first, I’ve tried running npm in a new project using npm init -y. I’ve tried removing node_modules, removing package-lock, ignoring package-lock, force-cleaning npm cache, resetting configs, all the jazz → didn’t work.
  • being on windows, I’ve followed this SO answer and completely removed node and npm → didn’t work.
  • I’ve tried fresh installing both node v10 and v11 → didn’t work.

What I’m currently running:

  • node v10.15.3
  • npm 6.4.1
  • windows 7

Thanks for help.

0 Likes

(John Gee) #2

It sounds like you might have NODE_ENV set to “production”, but that only explains the clean install without arguments: https://docs.npmjs.com/cli/install

With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies.

NOTE: The --production flag has no particular meaning when adding a dependency to a project.
1 Like

(David Luzar) #3

Mhm, now that’s embarrassing. I did a have NODE_ENV set to production. I not only missed that, but also the mention in the docs :blush:.

Turns out, in windows, removing an env variable is not simple. You need to run:

reg delete "HKCU\Environment" /v NODE_ENV /f

and reboot (or similar).

It fixed all the issues.

The mention of

NOTE: The --production flag has no particular meaning when adding a dependency to a project.

likely doesn’t relate to NODE_ENV, and thus affects even npm i -D installs.

Thanks for your help, who knows how long it’d take for me to notice the env var :).

1 Like

(system) closed #4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

0 Likes