15

I have npm v 1.2.32

When I run: $npm install mongo-migrate

it does not install mongodb which is a devDependency.

What am I doing wrong?

lostintranslation
  • 23,756
  • 50
  • 159
  • 262
  • Possible duplicate of [npm install won't install devDependencies](https://stackoverflow.com/questions/34700610/npm-install-wont-install-devdependencies) – Mouneer Jun 16 '17 at 15:46

5 Answers5

85

Although not directly related to this question, it may be of interest to some to know that if environment variable NODE_ENV is set to production, npm will ignore devDependencies when executing npm install.

bdukes
  • 152,002
  • 23
  • 148
  • 175
Gudlaugur Egilsson
  • 2,420
  • 2
  • 24
  • 23
  • This saved me another couple hours of comparing the differences in two dev environments. I had line-by-line compared the `npm config ls -l` right before I found this answer. Thanks! – bantic Apr 08 '15 at 20:23
  • The npm docs do actually include this note (https://github.com/npm/npm/commit/95e59b287c9517780318e145371a859e8ebb2d20), but their docs online are not up to date with that info yet. – bantic Apr 08 '15 at 20:35
  • upvote, is there a way to force npm install to install devDependencies in production ? Or should I just add the builded directory to my git repository ? – Dimitri Kopriwa Jul 15 '15 at 18:45
  • I work on windows and had to set my NODE_ENV to production globally. This answer really helped me. – Bas G Oct 22 '15 at 10:21
  • 6
    What value should I set for `NODE_ENV` to get it install devDependencies? – shenkwen Dec 29 '15 at 05:28
19

When you install a package from the NPM repository, dev dependencies won't automatically be installed as well (because those dependencies shouldn't be necessary to get the main package working properly).

You need to explicitly instruct npm to install dev dependencies too:

npm install mongo-migrate --dev

Update

The --dev command has been deprecated.

npm WARN install Usage of the --dev option is deprecated. Use --only=dev instead.

npm install mongo-migrate --only=dev
David Pine
  • 23,787
  • 10
  • 79
  • 107
robertklep
  • 198,204
  • 35
  • 394
  • 381
  • 1
    this is a bad answer. This command install devDepend recursively so that it's not usable most of the time – Yin Sep 15 '15 at 08:53
  • 2
    @Jake the answer is more than 2 years old. Feel free to create your own answer. – robertklep Sep 15 '15 at 08:55
2

npm i <package> # without devDependencies cd node_modules/<package> npm i # include devDependencies

"npm i --dev" is not correct, since it install devDependencies recursively.

Yin
  • 612
  • 7
  • 10
1

I just had this same issue only it was due to the fact that I had devDependencies defined twice in my package.json.

I had written it in manually misspelled and during troubleshooting ran some --save-dev installs which made it show up twice. Incidentally if you include the "devDependencies" twice in your package.json, npm will not install them.

Jesse Lee
  • 1,291
  • 1
  • 8
  • 20
0

I occasionally had to install devDependencies even with NODE_ENV=production.

I usually use this workaround.

// temporarily change NODE_ENV to other value...
NODE_ENV=development npm install