-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] npm uninstall -g
doesn't run the preuninstall
script
#3042
Comments
by design, npm does not have any lifecycle events/scripts that run during uninstall. I would agree that they should be there, but we would have to discuss it as part of our RFC process. @darcyclarke can we add this issue to the next RFC call? |
@wraithgar I wasn't aware that this was a design decision(?) This definitely did work in v6 (was able to replicate below), feels like a legitimate bug but I could be wrong... v6.14.12v7.9.0Our docs explicitly point out |
Some packages depend on a preuninstall hook: winser documents it to add and remove background processes on install/uninstall. I personally use it for an in-house cli tool that installs a local rest api that runs in the background at all times. When installing a new version this service needs to be uninstalled as to not cause file lock issues in Windows, and reinstalled so a newer version of this api is spun up. This is now causing issues in npm7. |
Good catch. I was looking at the Lifecyle Operation Order Which doesn't mention uninstall at all. The only place uninstall is mentioned is in that example itself. I agree this is now an arborist bug. |
Actions To Be Taken
|
I've audited the code and documentation and it appears to be correct. npm v6 & v7 take a very different approach to removing packages. The It would be difficult to present developers with clear documentation on all of the scenarios a package could be removed, and we don't currently have a mechanism for giving those scripts context on why the package was removed (duplicate, user action, changed dependency on a sub-package, changed semver spec requirement, etc). We could limit execution of uninstall scripts to when a root dependency or global is directly removed by a user, but it is unclear whether that would match the expected use cases or be sufficiently useful. In the future we could rework these lifecycle scripts to be executed with more context. |
Next Action Items needed:
|
Is there any kind of workaround here? I have a similar constellation as @Goobles and need the |
Current Behavior:
npm uninstall -g <package>
doesn't run thepreuninstall
scriptAlso,
npm install -g <package>
doesn't run thepreuninstall
script from the previously installed version of the same packageInstalling a newer version of a global package does trigger
preuninstall
in v6Expected Behavior:
npm uninstall -g <package>
should run thepreuninstall
scriptSteps To Reproduce:
Since npm7 removed console output for scripts during installation, so I echo something to a logfile instead.
npm pack
npm install -g ./testpackage-0.0.1.tgz
npm install -g ./testpackage-0.0.1.tgz
again (this should have triggeredpreuninstall
for the previous installation)npm uninstall -g testpackage
Images:
In v7:
In v6:
Environment:
The text was updated successfully, but these errors were encountered: