npm install not pulling in devDependencies

2019-04-19 20:09发布

问题:

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?

回答1:

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


回答2:

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.



回答3:

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

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



回答4:

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.



回答5:

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


标签: node.js npm