Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude NPM packages from update

Tags:

javascript

npm

I'm using npm for my React Native project and I'm trying to ignore few packages during npm update.

For example, I want to keep my React package always on [email protected]. But each time I run npm update it gets updated to [email protected].

Any ideas how could I do that?

like image 420
Ziya Avatar asked Jun 26 '18 13:06

Ziya


People also ask

Can you remove packages from npm?

The Node Package Manager (NPM) provides various commands that let you work with packages. And just as you can install a package from the npm library, you can uninstall it. To uninstall a package, you can use the command provided by npm for the purpose – npm uninstall .

Does npm install update packages?

The npm install installs all modules that are listed on package. json file and their dependencies. npm update updates all packages in the node_modules directory and their dependencies.


2 Answers

In your package.json file use "react": "~16.3.1" instead of "react": "^16.3.1" i.e. replace caret (which means equals or higher version) with tilda.

EDIT: @Gabriel Carnerio's point is valid. Tilda is for when minor version changes are ok. Remove it and use "react": "16.3.1" if you want exact v16.3.1

like image 80
vahdet Avatar answered Oct 03 '22 05:10

vahdet


It behaves depending on the Semantic Versioning of the NPM. Inside dependencies of your package.json file if the react version is specified as "react": "16.3.1", then your react version will not get updated.

like image 23
Paul Avatar answered Oct 03 '22 04:10

Paul