How do I prevent npm install from removing packages?

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/.


If your development flow involves updating in parallel packages which depend on one another, you might consider switching your project's package manager to from npm to yarn to take advantage of yarn's workspaces feature.

Yarns's workspaces allow you to easily setup a single monorepo containing all your interconnected dependencies, and let yarn thinking how to link them together in your dev environment.

Tags:

Node.Js

Npm