How to get npm to install a specific version of a package by default?

Is there a way to config npm to not install the package using the lazy version, for example:

"coffee-script": "^1.11.1", 

But

 "coffee-script": "1.11.1", 

And has this default behavior changed? Usually we don’t want to use lazy versions, I prefer to manually update everything to the last from time to time, rather than have an error appearing on my face after a new deployment due to an error in one of my dependencies.

The only way to "do this" right now is to manually remove the ^ character every time after every npm install , which is a little boring.

+6
source share
2 answers

This is the command that will set the user variable in your npm configuration to always default, in order to use the exact version when installing all packages by default.

Enter this command in the terminal:

 npm config set save-exact=true 

The new preference is saved in the npm user configuration file. He is here:

 ~/.npmrc 

Finally, you can verify that the parameter has been saved using the command:

 npm config ls 

NPM white papers here:

https://docs.npmjs.com/misc/config

https://docs.npmjs.com/files/npmrc

+4
source

I would suggest using npm shrinkwrap . It will create npm-shrinkwrap.json which indicates the currently used versions of your dependencies, and then npm install will abide by this.

Then, when you want to update all your dependencies, delete the npm-shrinkwrap.json file, run npm install and run npm shrinkwrap. Or, to update the dependency of a single package, run npm install --save <package-name> . This will update the npm-shrinkwrap file with updated version information.

See: https://docs.npmjs.com/cli/shrinkwrap

0
source

All Articles