Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM - How to install a new package without update or add packages described on package.json

This is a hard question and I'll try to explain.

How to add new packages without install dependencies or new packages (defined in package/-lock.json)?

For example: Currently, we have our package.json and package-lock.json to maintain the versioning.

However, If we try to add a new package, other packages (related to package.json or package-lock.json) are being updated/added.

The intention is just add new packages, add these packages info inside package.json and package-lock.json, without affect the current packages installed.

like image 458
Dan Avatar asked Feb 21 '18 17:02

Dan


People also ask

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.

Does npm install automatically add to json?

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 .

Can I manually add to package json?

You can add dependencies to a package. json file from the command line or by manually editing the package. json file.

What is npm clean install?

The npm clean-install command (or npm ci for short) is an in-place replacement for npm install with two major differences: It does a clean install: if the node_modules folder exists, npm deletes it and installs a fresh one. It checks for consistency: if package-lock.


2 Answers

Go to package.json and make some changes if you don't want any of your packages to update automatically. For example change "react-native": "^0.56.1" to "react-native": "0.56.1"

simply delete caret "^" or tilde "~" signs you see before version declarations.

  • Caret "^" sign makes npm able to update minor version updates (for above example 56 to 57 or higher) and
  • Tilde "~" sign makes npm able to update patch version updates (right-most element in [major, minor, path] tuple)

If you declare your package versions without any sign, they won't be updated.

like image 113
Amir Gorji Avatar answered Oct 27 '22 15:10

Amir Gorji


Use npm ci instead of npm install!

From the docs:

It will never write to package.json or any of the package-locks: installs are essentially frozen.

There are also other caveats and differences, I recommend to read the docs for more details. For example, it will remove existing node_module directories.

like image 31
Andreas Profous Avatar answered Oct 27 '22 14:10

Andreas Profous