Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force npm to install specific version of package by default?

Is there a way to config npm not to install package using a lazy version like:

"coffee-script": "^1.11.1",

But

"coffee-script": "1.11.1",

And have this behavior become the default one? We usually don't want to use lazy versions, I prefer to manually upgrade everything to the latest from time to time rather than having a bug thrown up at my face after a new deployment due to a bug in one of my dependencies.

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

like image 391
Vadorequest Avatar asked Oct 18 '16 10:10

Vadorequest


People also ask

How do I force an NPM package to install?

Run npm update -g npm. Execute this command by running the command prompt as Administrator npm install -g windows-build-tools. Run npm install inside the project folder where the package. json file is located, if it doesn't work run: npm install --force.

How do I change npm to specific version?

You can downgrade the npm version by specifying a version in the related commands. If you want to downgrade npm to a specific version, you can use the following command: npm install -g npm@[version.

Which of the following command is true to install a specific package and version?

NPM: Install Specific Version of a Package.


1 Answers

This is the command that will set a user variable in your npm configuration to always default to use the exact version when performing an npm installation of all packages.

Enter this command in your terminal:

npm config set save-exact=true

The new preference is stored in a user-based custom npm configuration file. It is located here:

~/.npmrc

Finally, you can verify the setting was saved with the command:

npm config ls

Official NPM docs here:

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

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

like image 162
emveeoh Avatar answered Sep 30 '22 20:09

emveeoh