`npm unlink foo` doesn't reinstall the "real" `foo`


(Jeffrey Wear) #1

Imported from https://github.com/npm/npm/issues/20995.

I’m opening this issue because:

npm is producing incorrect or undesirable behavior.

What’s going wrong?

npm unlink foo doesn’t reinstall the “real” foo. Even worse, it modifies my package.json to completely remove foo. To fix these issues, I have to do npm unlink --no-save foo && npm install.

This behavior is confusing because it means that npm unlink is not a mirror of npm link:

  • npm link ../foo overwrites the “real” foo with the version of foo at ../foo, but npm unlink foo doesn’t replace ../foo with the “real” foo
  • npm link ../foo doesn’t modify my package.json (to e.g. say dependencies: { foo: "../foo" }), but npm unlink foo modifies my package.json to remove foo

I realize that this behavior occurs because npm unlink is merely an alias for npm uninstall, as shown by running npm unlink -h. But I do not think it should be an alias, but rather its own command with its own behavior.

It seems like this is a partial design goal for you folks per https://github.com/npm/npm/issues/6248, "npm link and npm unlink should be mirror operations"… but I don’t understand how you can consider them mirror operations if npm unlink === npm uninstall.

TL;DR npm unlink foo should made to behave like npm unlink --no-save foo && npm install, to make npm unlink foo the mirror of npm link ../foo.

How can the CLI team reproduce the problem?

As per the commands in the previous section, s/foo/any-real-package. I am glad to provide a test package if necessary.

supporting information:

  • npm -v prints: 6.0.0
  • node -v prints: 8.9.3
  • npm config get registry prints: registry.npmjs.org
  • Windows, OS X/macOS, or Linux?: OS X

(Jeffrey Wear) #2

Interestingly, it appears that if I do npm unlink ../foo, then the real module will be reinstated, and not removed from package.json, although npm may still make other modifications to package.json like alphabetizing the dependencies.

TL;DR npm unlink ../foo appears to be a shorter workaround than npm unlink --no-save foo && npm install.


(Kat Marchán) #3

The entire story about linking/unlinking/local files/temp linking/etc is going to change enormously once the new link RFC is ratified and implemented, so I’d suggest giving feedback in that RFC to make sure your use case is covered if you don’t think it currently is:

https://npm.community/t/new-npm-link-command/24/2


(Jeffrey Wear) #4

That RFC looks like it’ll do the trick, thanks @zkat!


(system) #5

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.