Can't use third-party modules in uninstall hook #11894
Comments
|
It's little surprise that we had some lifecycle-related changes after It's possible that |
|
I tried this and I can't reproduce it in 3.7.3 or 3.8.1: |
|
Thank you very much for the feedback. ~ $ mkdir uninstall
~ $ cd uninstall/
~/uninstall $ npm -v
3.7.3
~/uninstall $ node -v
v5.8.0
~/uninstall $ mkdir a
~/uninstall $ cat > a/package.json
{
"name": "a",
"version": "1.0.0",
"scripts": {
"uninstall": "node uninstall.js"
},
"dependencies": {
"chalk": "*"
}
}
^C
~/uninstall $ cat > a/uninstall.js
var chalk = require('chalk')
console.log(chalk.green('done'))
^C
~/uninstall $ mkdir node_modules
~/uninstall $ npm install a
/Users/aaron/uninstall
└─┬ a@1.0.0
└─┬ chalk@1.1.1
├─┬ ansi-styles@2.2.0
│ └── color-convert@1.0.0
├── escape-string-regexp@1.0.5
├─┬ has-ansi@2.0.0
│ └── ansi-regex@2.0.0
├── strip-ansi@3.0.1
└── supports-color@2.0.0
npm WARN enoent ENOENT: no such file or directory, open '/Users/aaron/uninstall/package.json'
npm WARN uninstall No description
npm WARN uninstall No repository field.
npm WARN uninstall No README data
npm WARN uninstall No license field.
~/uninstall $ npm uninstall a
> a@1.0.0 uninstall /Users/aaron/uninstall/node_modules/a
> node uninstall.js
module.js:341
throw err;
^
Error: Cannot find module 'chalk'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/Users/aaron/uninstall/node_modules/a/uninstall.js:1:75)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
npm WARN lifecycle a@1.0.0~uninstall: continuing anyway a@1.0.0 uninstall: `node uninstall.js`
npm WARN lifecycle Exit status 1
- a@1.0.0 node_modules/a
- ansi-regex@2.0.0 node_modules/ansi-regex
- ansi-styles@2.2.0 node_modules/ansi-styles
- chalk@1.1.1 node_modules/chalk
- color-convert@1.0.0 node_modules/color-convert
- escape-string-regexp@1.0.5 node_modules/escape-string-regexp
- has-ansi@2.0.0 node_modules/has-ansi
- strip-ansi@3.0.1 node_modules/strip-ansi
- supports-color@2.0.0 node_modules/supports-color
npm WARN enoent ENOENT: no such file or directory, open '/Users/aaron/uninstall/package.json'
npm WARN uninstall No description
npm WARN uninstall No repository field.
npm WARN uninstall No README data
npm WARN uninstall No license field.
~/uninstall $ Do you want me to try something else? I've also tried to read ~/uninstall $ npm install a
~/uninstall $ cat > node_modules/a/uninstall.js
console.log(require('fs').readdirSync(__dirname + '/..'))
^C
~/uninstall $ npm uninstall a
> a@1.0.0 uninstall /Users/aaron/uninstall/node_modules/a
> node uninstall.js
[ '.staging', 'a' ]
- a@1.0.0 node_modules/a
- ansi-regex@2.0.0 node_modules/ansi-regex
- ansi-styles@2.2.0 node_modules/ansi-styles
- chalk@1.1.1 node_modules/chalk
- color-convert@1.0.0 node_modules/color-convert
- escape-string-regexp@1.0.5 node_modules/escape-string-regexp
- has-ansi@2.0.0 node_modules/has-ansi
- strip-ansi@3.0.1 node_modules/strip-ansi
- supports-color@2.0.0 node_modules/supports-color
npm WARN enoent ENOENT: no such file or directory, open '/Users/aaron/uninstall/package.json'
npm WARN uninstall No description
npm WARN uninstall No repository field.
npm WARN uninstall No README data
npm WARN uninstall No license field. |
|
Here is a repository with a repro of this bug: https://github.com/NotMyself/ghost-azurestorage Note that |
|
I have also run into this issue (uninstall.js requires a module that gets uninstalled right before that) However, the minimum working example from @iarna did not trigger the bug for me. But in the real world the bug gets triggered. My versions:
|
Make uninstall.js independent of 3rd party modules. There is an npm v3 bug that (sometimes) uninstalls 3rd party modules before running your uninstall script which may rely on those modules. Refs npm/npm#11894
Make uninstall.js independent of 3rd party modules. There is an npm v3 bug that (sometimes) uninstalls 3rd party modules before running your uninstall script which may rely on those modules. Refs npm/npm#11894
Make uninstall.js independent of 3rd party modules. There is an npm v3 bug that (sometimes) uninstalls 3rd party modules before running your uninstall script which may rely on those modules. Refs npm/npm#11894
|
We're facing this problem too, seen on Windows and OS X, both through It seems to me there's a racing condition sometimes moving When |
Due to a bug in npm[1], there is a racing condition where node_modules sometimes gets removed (or moved away) before preuninstall scripts start. As a consequence, 'module not found' errors break the uninstallation workflow. [1]: npm/npm#11894
|
Because I was affected by this, and apparently this is already a problem for more then 1 year, I created a repository that illustrates the problem. https://github.com/SamVerschueren/npm-iss11894
npm: v3.10.8 |
|
|

Hey folks,
I can't find anything in issues or changelog. It worked with Node 0.12 (npm 2.14.9) but fails with 4 and 5 (npm 3.7.3).
In 4+ third-party modules are uninstalled before running uninstall hook making it impossible to require them in uninstall script.
Not being able to require modules makes it complicated to clean stuff on uninstall.
Is it a new feature or a bug or is there a new better way to do cleaning?
uninstall.js
package.json
The text was updated successfully, but these errors were encountered: