Yarn: `yarn remove package` doesn't trigger `preuninstall` and `postuninstall` scripts

Created on 13 Jun 2017  ·  7Comments  ·  Source: yarnpkg/yarn

What is the current behavior?
there is a preuninstall and postuninstall in my package.json:

"scripts": {
  "preuninstall": "echo 'pre uninstall'",
  "postuninstall": "echo 'post uninstall'"
}

but yarn remove package doesn't trigger them:

$ yarn remove ignore-loader
yarn remove v0.26.1
[1/2] Removing module ignore-loader...
[2/2] Regenerating lockfile and installing missing dependencies...
warning "[email protected]" has incorrect peer dependency "[email protected] || 0.20.x".
success Uninstalled packages.
Done in 33.05s.

If the current behavior is a bug, please provide the steps to reproduce.

reproduce steps:

  1. config preuninstall and postuninstall scripts in package.json
  2. run yarn remove package
  3. check stdout

What is the expected behavior?

preuninstall and postuninstall should be triggered like yarn add package triggers preinstall and postinstall.

Please mention your node.js, yarn and operating system version.

  • nodejs: v6.9.1
  • os: Mac OSX 10.12.4
  • yarn: v0.26.1
help wanted triaged

Most helpful comment

There's a workaround via the postinstall-postinstall package, in case anyone stumbles across this years later... ;)

All 7 comments

The scripts are relative to the package, so if I understand the original issue correctly, yarn remove ignore-loader should trigger the scripts for ignore-loader package, not the ones on your own package.json--those get triggered when your package gets removed. So I think this already works as expected.

Yeah, seems right

There's a workaround via the postinstall-postinstall package, in case anyone stumbles across this years later... ;)

@stigi that package doesn't seem to work for me (using yarn 1.16.0); postuninstall is never triggered

@kangax True, only works to call postinstall after add or remove. It's called postinstall-postinstall not postuninstall-postuninstall after all 🤷‍♂️

@stigi good point, I guess I'll just whip up postuninstall-postuninstall then 🙃

Was this page helpful?
0 / 5 - 0 ratings