17

I am trying to do local development of an NPM package and test it in a package which depends on it. I'm using NPM (7.5.3) and specifically npm link for this but running into a problem with the chain of dependencies.

The child package has dependencies, these are all added to the parent's node_modules folder when using npm install "git+https://github.com/name/child_package". But when I npm link that module:

cd child_package
npm link
cd ../parent_package
npm link child_package

With the last command run (npm link child_package), all of the dependencies for child_package which were in the node_modules of parent_package are removed. NPM reporting:

removed 60 packages, changed 1 package, and audited 231 packages in 1s

At which point all the compilation in the parent package fails due to the missing deps. It finds the child_package, which is symlinked as expected, but dependency defined in child_package of "gsap" has now been removed.

If I reinstall it using npm install "git+https://github.com/name/child_package" it will add the deps back into the node_modules folder of the parent project.

buckaroo1177125
  • 1,555
  • 11
  • 22
  • 6
    Yup, happening to me too. This is supremely annoying. – Michael Liu Mar 18 '21 at 03:38
  • Checkout Lerna https://github.com/lerna/lerna if you haven't already. It will allow you to bootstrap packages - e.g. install the child_package's dependencies and then the parent. If the child is also available locally. You can then simply do an npm link without blowing away anyones dependencies – jeeves Aug 04 '21 at 16:18

2 Answers2

1

try to do the following:

cd child_package
npm install

that will install child dependencies to directory of child package

personally I hate npm link and always use npm publish (use version number like 1.0.0-preview.1 for your child package and remove '-preview.Number' when you are done)

Andrey
  • 1,752
  • 18
  • 17
  • 1
    Tried this, doesn't work. When I try to run the main project (that i linked the package into) it still complains of the missing deps. The goal with link to is develop on the child package, so not sure how publish would be a better alternative thank link? – meeech Aug 06 '21 at 00:27
1

This is a behavior introduced in npm V7 + .

The only reasonable "workaround" i have found is to go back to npm 6 (npm install -g npm@6).

Another "workaround" is to npm install --no-save ../../my-local-module but to reflect changes to the local module you will need to delete it from node_modules and reinstall again. Kind of lame....

Jasminen
  • 29
  • 4