Skip to content

[BUG] npm dedupe -g removes some globally installed packages #2620

@markSmurphy

Description

@markSmurphy

Current Behaviour:

I have some npm packages installed globally, which are command line utilities (create-react-app, distributed-dig, snyk`, and others). I recently updated to npm version 7 (7.5.2) with node 14 (14.15.4) on Windows 10 (version: 2004 || build: 19041.746).

If I perform a global dedupe ...

npm dedupe -g

... a number of the globally installed packages are removed. Curiously not all of them. In the example below eight of the 11 are removed.

Incidentally, I couldn't reproduce this behaviour with npm v7.5.2 & node v15.5.1 on Linux Mint v19

Expected Behaviour:

I'd expect the same behaviour as npm v6 where each top-level globally installed package persists after the global dedupe. In the example steps below I'd expect all 11 globally installed packages to still be installed after the dedupe.

Steps To Reproduce:

Report current versions: npm -v ; node -v

PS C:\Users> npm -v;node -v
7.5.2
v14.15.4

List currently installed global packages (and report a count): npm ls -g --depth 0;npm ls -g --depth 0|find "--" /c

PS C:\Users> npm ls -g --depth 0;npm ls -g --depth 0|find `"--`" /c
C:\Users\markm\AppData\Roaming\npm
+-- akamai-error-lookup@1.2.8
+-- akamai-staging@1.1.8
+-- ascii-art@2.5.0
+-- cdn-cache-check@1.6.0
+-- codename-generator@1.0.15
+-- create-react-app@4.0.2
+-- depcheck@1.3.1
+-- distributed-dig@1.8.3
+-- eslint@7.19.0
+-- jshint@2.12.0
+-- npm@7.5.2
`-- snyk@1.441.0

12

Perform a global dedupe: npm dedupe -g

PS C:\Users> npm dedupe -g

added 1 package, removed 1334 packages, and audited 256 packages in 6s

11 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Notice that removed 1334 packages

Re-list globally installed packages (and a new count): npm ls -g --depth 0;npm ls -g --depth 0|find "--" /c

PS C:\Users> npm ls -g --depth 0;npm ls -g --depth 0|find `"--`" /c
C:\Users\markm\AppData\Roaming\npm
+-- acorn-jsx@5.3.1
+-- npm@7.5.2
`-- prettyjson@1.2.1

3

Eight of the the initial 11 global packages are now removed
2021-02-04_12h19_39

Environment:

  • OS: Windows 10 (version: 2004 || build: 19041.746)
  • Node: 14.15.4
  • npm: 7.5.2
  • PowerShell 7.1.1 (although I still see this behaviour when using cmd.exe instead:
    2021-02-04_13h27_40

Metadata

Metadata

Assignees

Labels

Bugthing that needs fixingRelease 7.xwork is associated with a specific npm 7 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions