Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent npm install from removing packages?

Tags:

node.js

npm

I'm trying to set up a development environment with several packages, and as a result I need to manually install some dependencies. More specifically, I have some local changes in several packages which I need to test before I can push them to github, so I can't just npm install the top level because it won't pick up those change. So I run the first npm install manually on packages which are missing, and then try to run my node code and see which package it is still missing, then try to npm install what it says is missing.

However, when I go to install the second package, it ends up with this message:

added 3 packages from 4 contributors, removed 799 packages and audited 3 packages in 4.197s

The second install removed practically every package that was already installed! I didn't notice this until about the third time, when I realized that I seemed to be installing the same thing over and over.

However can I prevent this particularly naughty behavior and force npm to only install what I tell it to and leave everything else alone?

like image 303
Michael Avatar asked Jul 21 '18 03:07

Michael


1 Answers

Have a look at npm link if you need to test against modified packages.

From npm link: This is handy for installing your own stuff, so that you can work on it and test it iteratively without having to continually rebuild.

Say b is a dependency of a. You made changes to b and want to check if a still works with those changes. Instead of using b in node_modules installed from npm, use your local, modified version:

cd ~/projects/b    # go into the package directory
npm link           # creates global link
cd ~/projects/a    # go into some other package directory.
npm link b         # link-install the package

Now, any changes to ~/projects/b will be reflected in ~/projects/a/node_modules/b/.

like image 185
user835611 Avatar answered Sep 18 '22 09:09

user835611