npm install won't install devDependencies

node.jsNpm

node.js Problem Overview


On windows for some reason when I run npm install it won't install devDependencies. AFAIK it should. If I run npm install --dev devDependencies are installed. I don't understand why npm install doesn't install devDependencies too, but installs only dependencies. What could be the reason? How can I fix it?

Maybe something is wrong with my package.json? It is listed below if it may be helpful:

{
  "name": "try-brunch",
  "version": "0.1.0",
  "private": "true",
  "devDependencies": {
    "brunch": "^2.0.4",
    "cssnano-brunch": "^1.1.5",
    "javascript-brunch": "^1.8.0",
    "sass-brunch": "^1.9.2",
    "uglify-js-brunch": "^1.7.8"
  },
  "dependencies": {
    "jquery": "^2.1.4"
  }
}

node.js Solutions


Solution 1 - node.js

Check the NPM docs for install

> With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies." > > The --only={prod[uction]|dev[elopment]} argument will cause either only devDependencies or only non-devDependencies to be installed regardless of the NODE_ENV."

Have you tried

npm install --only=dev

If you are worried that your package.json might be incorrect, best thing to do is this. Create a new folder, and run:

npm init --yes

Then:

npm install --save-dev brunch@^2.0.4
npm install --save-dev cssnano-brunch@^1.1.5
npm install --save-dev javascript-brunch@^1.8.0
npm install --save-dev sass-brunch@^1.9.2
npm install --save-dev uglify-js-brunch@^1.7.8
npm install jquery@^2.1.4 --save

And you should be good to go! Otherwise, will keep posting other options.

Check your npm configuration:

npm config list

npm gets its config settings from the command line, environment variables, and npmrc files. So check environment variables, and the npmrc file.

Still failing?

Ok, create a new folder, ideally somewhere else on your filesystem. ie. not in same folder hierarchy. For instance, C:\myNewFolder - the closer to the base C: drive the better.

Then run:

npm init --yes

Now run:

npm install underscore --save

and finally:

npm install mocha --save-dev

Does everything work as expected?

What I am trying to do is understand whether your problem is global, or something local to the previous folder and dependencies.

Solution 2 - node.js

Check if npm config production value is set to true. If this value is true, it will skip over the dev dependencies.

Run npm config get production

To set it: npm config set -g production false

Solution 3 - node.js

make sure you don't have env variable NODE_ENV set to 'production'.

If you do, dev dependencies will not be installed without the --dev flag

Solution 4 - node.js

I had a package-lock.json file from an old version of my package.json, I deleted that and then everything installed correctly.

Solution 5 - node.js

You can use the short way for installation dependencies only for development as follows:

npm i -D <dependencies-names>

Solution 6 - node.js

I had a similar problem. npm install --only=dev didn't work, and neither did npm rebuild. Ultimately, I had to delete node_modules and package-lock.json and run npm install again. That fixed it for me.

Solution 7 - node.js

Make sure your package.json is valid...

I had the following error...

npm WARN Invalid name: "blah blah blah"

and that, similarly, caused devDependencies not to be installed.

FYI, changing the package.json "name" to blah-blah-blah fixed it.

Solution 8 - node.js

I have the same issue because I set the NODE_ENV=production while building Docker. Then I add one more npm install --only=dev. Everything works fine. I need the devDependencies for building TypeSciprt modules

RUN npm install
RUN npm install --only=dev

Solution 9 - node.js

So the way I got around this was in the command where i would normally run npm install or npm ci, i added NODE_ENV=build, and then NODE_ENV=production after the command, so my entire command came out to:

RUN NODE_ENV=build && npm ci && NODE_ENV=production

So far I haven't had any bad reactions, and my development dependencies which are used for building the application all worked / loaded correctly.

I find this to be a better solution than adding an additional command like npm install --only=dev because it takes less time, and enables me to use the npm ci command, which is faster and specifically designed to be run inside CI tools / build scripts. (See npi-ci documentation for more information on it)

Solution 10 - node.js

Got a similar error after running npm-check-updates -u. Solved it by removing node_modules folder and package-lock.json. After that a new npm install and everything worked.

My exception:

> Failed to load parser '@typescript-eslint/parser' declared in > 'package.json » eslint-config-react-app#overrides[0]': Cannot find > module '@typescript-eslint/parser'

Solution 11 - node.js

In my case, the problem was that I had the NODE_ENV variable set to production in the same terminal session I ran npm install.

For my build to run properly I was not allowed to change the value of NODE_ENV so I forced npm to install all the dependencies by adding the --production=false flag to it: npm install --production=false as mentioned in the docs.

If you don't need NODE_ENV to be set to production you can simply type export NODE_ENV=development to your terminal to overwrite its value and run npm install again.

Solution 12 - node.js

As @Ale told, we can use npm i -D <some_module_name> or npm i --save-dev <some_module_name> now. It seems command was changed at some point of node version. Offical (npm dependencies and devDependencies) says following.

> When you add the -D flag, or --save-dev, you are installing it as a development dependency, which adds it to the devDependencies list.

Solution 13 - node.js

As of now you could use:

npm i --also=dev

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTristan TzaraView Question on Stackoverflow
Solution 1 - node.jsarcseldonView Answer on Stackoverflow
Solution 2 - node.jsShawn McleanView Answer on Stackoverflow
Solution 3 - node.jsNir LevyView Answer on Stackoverflow
Solution 4 - node.jsuser2929830View Answer on Stackoverflow
Solution 5 - node.jsAleView Answer on Stackoverflow
Solution 6 - node.jsobsessiveprogrammerView Answer on Stackoverflow
Solution 7 - node.jsAlex GrayView Answer on Stackoverflow
Solution 8 - node.jsPhat TranView Answer on Stackoverflow
Solution 9 - node.jsJakGuruView Answer on Stackoverflow
Solution 10 - node.jsOgglasView Answer on Stackoverflow
Solution 11 - node.jsFeri ForgacsView Answer on Stackoverflow
Solution 12 - node.jsJackView Answer on Stackoverflow
Solution 13 - node.jsAmiNadimiView Answer on Stackoverflow