cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] npm unlink breaking change intentional?

Open rafgraph opened this issue 6 years ago • 9 comments

Current Behavior:

In a package directory where npm link has been run (to link the package in global node_modules), running npm unlink gives the error must provide a package name to remove. In v6 running npm unlink in this situation would remove the link to the package in global node_modules. In v7 I can run npm unlink -g <package-name> to remove the link in global node_modules so I'm not sure if this is a bug or an intentional deprecation of npm unlink to remove the package from global node_modules?

Expected Behavior:

For npm unlink to remove the link to the package in global node_modules

Steps To Reproduce:

Run npm link && npm unlink in a package directory.

Environment:

  • OS: MacOS 10.15.7
  • Node: 12.18.3
  • npm: 7.0.0-rc.4

rafgraph avatar Oct 12 '20 02:10 rafgraph

Hm, this isn't an intentional change, afaik, and should not be too hard to fix.

You can do this in npm 7 with npm unlink -g, but we just aren't defaulting the -g when no args are specified.

isaacs avatar Oct 22 '20 23:10 isaacs

Thanks, I've been using npm unlink -g and like the added -g. Makes it clear what I'm doing. So closing.

rafgraph avatar Dec 20 '20 20:12 rafgraph

I think this should be reopened. At the very least, npm unlink doesn't have a doc page; this issue is the only way of knowing that we should use npm unlink -g instead

j-m avatar May 14 '21 14:05 j-m

Doesn't this break the symmetry between npm link and npm unlink? I'd vote to reopen as well.

jp-simons avatar May 30 '21 23:05 jp-simons

at least this issue is in the google results :D thanks for the workaround!

Aprillion avatar Jul 20 '21 11:07 Aprillion

This is the only way we know of needing to add -g, which I think should be indicated in the documentation😀

wangrongding avatar Mar 28 '22 15:03 wangrongding

For me worked sudo npm link && sudo npm unlink -g <package-name> package-name is "name" in package.json

ghost avatar May 28 '22 19:05 ghost

Can someone tell me difference between npm unlink and npm unlink -g npm unlink -g is working for me, but the tutorial I am following uses npm unlink

kgpyi avatar Jun 22 '22 12:06 kgpyi

@kgpyi I believe the -g stands for global. I think the reason for all this is because unlink is actually an alias for uninstall so you are uninstalling the package globally.

MrBrN197 avatar Jun 29 '22 08:06 MrBrN197