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?
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.EDIT 2016/09/13
I've tested out npm v3.10.8, and this functionality now works as expected. We've shrinkwrapped our devDependencies and can install only prod dependencies when we deploy.
I think it's worth mentioning that this feature should start working as expected very soon. According to this github issue, tons of people were running into the same problem, and according to this pull request, it will be in the next release (scheduled for 2016-09-08).
With the pull request merged in, all you would have to do is:
This is fixed in
npm
3.10.8
;npm install --production
shouldn't install dev deps in a shrinkwrap created bynpm shrinkwrap --dev
: https://github.com/npm/npm/releases/tag/v3.10.8September, 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:2013 answer:
As stated in the NPM docs:
Basically, or you lock down all deps, or only the production deps.
Not even running
npm install --dev
ornpm install --force
can transcend the shrinkwrap functionality.As to npm 5 (I've tried on 5.5.1 and 5.6.0), --production (--only=prod) flag is problematic.
When package-lock.json exists in the folder,
simply changes the file name to npm-shrinkwrap.json.
How I managed to solve this issue is to run:
and then run: