Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to shrinkwrap devDependencies, but not install them unless necessary?

Tags:

node.js

npm

I have a bunch of devDependencies needed in order to run test suite and have production dependencies locked down with npm shrinkwrap. The problem is that when I run npm install, only production dependencies are installed, in order to install devDependencies, I have to remove npm-shrinkwrap.json and run it again.

Now if shrinkwrap contains devDependencies as well, they get installed in production, where they are not required. Surely there should be some command line arguments to force only normal dependencies to be installed?

like image 571
Fluffy Avatar asked Jul 09 '13 08:07

Fluffy


People also ask

Is -- save Dev necessary?

There is no noticable difference between --save and --save-dev when developing. To take the moment. js example: when running webpack, the moment code is taken from node_modules and included in the project. In this sense there is no difference with typescript which is also needed when running webpack.

How do I skip a package in npm install?

To skip Installation of devDepenencies pass --production flag to npm install ,with the --production flag(or NODE_ENV environment variable set to production ) npm will not install modules listed in devDependencies." To make any module to be part of devDependencies pass --dev while installing.

How do you save devDependencies?

To add dependencies and devDependencies to a package. json file from the command line, you can install them in the root directory of your package using the --save-prod flag for dependencies (the default behavior of npm install ) or the --save-dev flag for devDependencies.

Does npm install installs devDependencies?

By default, npm install will install all modules listed as dependencies in package. json . With the --production flag (or when the NODE_ENV environment variable is set to production ), npm will not install modules listed in devDependencies .


2 Answers

September, 2016:

As others have mentioned as well, there were some huge efforts to enhance the shrinkwrap feature starting with npm v3.10.8.

Thanks to this, it'll be possible to keep your devDependencies locked while installing only the production dependencies:

npm shrinkwrap --dev npm install --only=prod 

2013 answer:

As stated in the NPM docs:

Since npm shrinkwrap is intended to lock down your dependencies for production use, devDependencies will not be included unless you explicitly set the --dev flag when you run npm shrinkwrap. If installed devDependencies are excluded, then npm will print a warning. If you want them to be installed with your module by default, please consider adding them to dependencies instead.

Basically, or you lock down all deps, or only the production deps.

Not even running npm install --dev or npm install --force can transcend the shrinkwrap functionality.

like image 152
gustavohenke Avatar answered Oct 12 '22 19:10

gustavohenke


It looks like this feature was recently added in v3.3 of the npm client per the changelog

You'll now be able to run npm install --only=prod to achieve the effect you wish.

like image 41
Whoaa512 Avatar answered Oct 12 '22 20:10

Whoaa512