Skip to content

[BUG] npm uninstall -g doesn't run the preuninstall script #3042

@Goobles

Description

@Goobles

Current Behavior:

npm uninstall -g <package> doesn't run the preuninstall script

Also, npm install -g <package> doesn't run the preuninstall script from the previously installed version of the same package

Installing a newer version of a global package does trigger preuninstall in v6

Expected Behavior:

npm uninstall -g <package> should run the preuninstall script

Steps To Reproduce:

Since npm7 removed console output for scripts during installation, so I echo something to a logfile instead.

  1. Create a package with these scripts:
{
  "name": "testpackage",
  "version":"0.0.1",
  "scripts": {
    "preinstall": "echo \"preinstall\" >> /logs/log.txt",
    "preuninstall": "echo \"preuninstall\" >> /logs/log.txt"
  }
}
  1. run npm pack
  2. run npm install -g ./testpackage-0.0.1.tgz
  3. run npm install -g ./testpackage-0.0.1.tgz again (this should have triggered preuninstall for the previous installation)
  4. run npm uninstall -g testpackage
  5. confirm that the text file in /logs/log.txt does in fact not contain any 'preuninstall' lines

Images:
In v7:
Code_kIGgtizrAQ
In v6:
Code_RSlxOsyZwd

Environment:

  • OS: Windows 10
  • Node: 15.14.0
  • npm: 7.7.6

Metadata

Metadata

Assignees

Labels

Bugthing that needs fixingPriority 1high priority issueRelease 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