373

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"
  }
}
norbitrial
  • 14,716
  • 7
  • 32
  • 59
tristantzara
  • 5,597
  • 6
  • 26
  • 40
  • Say you write an app, and you need a logger or webpack plugin. those are devdeps. those need to be installed. npm doesn't install those in some cases. – tristantzara Mar 08 '18 at 11:30
  • 3
    I mean, the installation for `devDependencies` is needed only when you **write** the package (application). Using it does not require the `devDependencies`. So **it is reasonable for `devDependencies` to require extra flags to be installed.** If `npm install` installed `devDependencies` **by default**, the _users_ would get redundant packages as well. – Константин Ван Mar 08 '18 at 13:45
  • 5
    the documented behaviour is that when I do `npm i` in my folder it grabs py `package.json` and installs both deps and devdeps. This is the way it's intended to work and it makes sense (e.g. when I do `npm i` after `git clone` I expect to have all I need, including e.g. webpack plugins). This question addresses a bug, when the actual behaviour is different from intended. pls, take a look at docs - https://docs.npmjs.com/cli/install . There's a flag to not install devdeps, but the default behavior is to install them, which makes perfect sense and is what everybody expects – tristantzara Mar 08 '18 at 14:57
  • 1
    I don't see any sane reasons to make me remember to run another command to install e.g. webpack plugins or typescript type defs or any other devdeps every time I pull. `npm i` should bootstrap both, which is the intended, sane and documented behavior, so I honestly don't understand why you say that this issue should be a standard – tristantzara Mar 08 '18 at 14:59
  • 1
    regarding your point that `Using it does not require the devDependencies` - I'm a bit confused. When I run `npm i` on CI or server my app needs e.g. typescript, jest, webpack, whatever devdeps to get built, so I don't get which `using` was this about – tristantzara Mar 08 '18 at 15:06
  • `when I do npm i in my folder it grabs my package.json and installs both deps and devdeps.` -- Okay, it seems we're arguing on different things: (what I'm saying is) installing already-published packages with `npm install `, and (what you're saying is) `npm install`ing with your local `package.json`. – Константин Ван Mar 08 '18 at 18:31
  • The context in which I said `using` is this: [“If someone is planning on downloading and **using your module in their program**, then they probably don't want or need to download and build the external test or documentation framework that you use. **In this case,** it's best to map these additional **items in a `devDependencies` object.**”](https://docs.npmjs.com/files/package.json#devdependencies). – Константин Ван Mar 08 '18 at 18:31
  • 1
    I'm sorry for misreading the question and offending you. This is my fault mistaking your context. – Константин Ван Mar 08 '18 at 18:31
  • no worries. yes, it was about installing kinda my devdeps, not devdeps of libs. There might be issues with those as well, but I haven't yet ran into such – tristantzara Mar 09 '18 at 10:39
  • @КонстантинВан Because it need to be installed under Jenkins by scripts. – towry Mar 06 '20 at 01:02

13 Answers13

423

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.

Community
  • 1
  • 1
arcseldon
  • 35,523
  • 17
  • 121
  • 125
  • 7
    npm install --only=dev installs devdeps, but I would like to install both deps and devdeps at once. package.json seems to be ok, as recreating it doesn't change anything. Am I right that NODE_ENV exists both globally, as a default value and locally, as a value for project? Where can I check and change these values on windows (I've looked and I have no system variable NODE_ENV) – tristantzara Jan 12 '16 at 09:37
  • @TristanTzara - i work almost exclusively on MAC these days. However, from memories of days gone by (years ago on NT and XP) - can you type something like "set" into command prompt window.. Else go to something like System Properties -> Advanced -> Environment Variables and check your entries there. You are looking for a "key" with NODE_ENV. I will google now for a windows option but posted this in case it helps. – arcseldon Jan 12 '16 at 09:46
  • Link here - http://winaero.com/blog/how-to-see-names-and-values-of-environment-variables-in-windows-8-and-windows-7/ – arcseldon Jan 12 '16 at 09:48
  • @TristanTzara - that is good to know. One thought, check all the parent directories above your directory that doesn't work. Look for an existing node_modules folder... npm will search upwards when trying to resolve a dependency and it might be something weird like it is picking up an existing installed module further up the directory tree, and therefore refusing to install yours in the child folder. The usual place is right under your home directory.. Good luck and thanks for acknowledging my answer :D – arcseldon Jan 12 '16 at 10:40
  • Or just copy your failing package.json file to a folder you know works, and see if you get different results (working) at that new location. – arcseldon Jan 12 '16 at 10:42
  • 5
    `npm install && npm install --only=dev` Thanks! – prograhammer Mar 20 '19 at 14:50
  • 5
    Also `only` option is deprecated, you could use either `omit` or `include` which better suits you. – monk Feb 26 '21 at 23:01
  • `@devDependencies` !== `devDependencies`. FML – J-Cake May 02 '22 at 07:17
109

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

Shawn Mclean
  • 56,733
  • 95
  • 279
  • 406
  • I wonder if, somewhere between npm 5.x and npm 6.x, if no value was set, the default become `true` rather than `false`? – James Perih Jun 19 '18 at 19:49
60

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

Nir Levy
  • 12,750
  • 3
  • 21
  • 38
27

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

npm i -D <dependencies-names>
Alejandro
  • 809
  • 1
  • 10
  • 21
23

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

16

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.

obsessiveprogrammer
  • 1,344
  • 1
  • 9
  • 8
10

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
Phat Tran
  • 3,404
  • 1
  • 19
  • 22
10

As of now you could use:

npm i --also=dev
AmiNadimi
  • 5,129
  • 3
  • 39
  • 55
7

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.

Alex Gray
  • 16,007
  • 9
  • 96
  • 118
6

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 npm-ci documentation for more information on it)

r g
  • 3,586
  • 1
  • 11
  • 27
JakGuru
  • 101
  • 1
  • 8
3

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.

Feri Forgacs
  • 101
  • 1
  • 4
2

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'

Ogglas
  • 62,132
  • 37
  • 328
  • 418
0

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.

Jack
  • 125
  • 1
  • 1
  • 10