npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

Cannot remove global package which was installed from local tgz file if said tgz file is removed

What I Wanted to Do

I tried to uninstall a package installed with --global. The package was installed via a tgz file generated with npm pack. I had since removed this tgz file.

What Happened Instead

When running npm rm -g package-name, I get an ENOENT error about the tgz file used to install the package.

npm ERR! path /home/kristjan/tmp/global-package/global-package-1.0.0.tgz
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall stat
npm ERR! enoent ENOENT: no such file or directory, stat '/home/kristjan/tmp/global-package/global-package-1.0.0.tgz'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/kristjan/.npm/_logs/2019-03-28T13_28_33_901Z-debug.log

Reproduction Steps

mkdir global-package
cd global-package
npm init -y
npm pack
npm i -g global-package-1.0.0.tgz
rm global-package-1.0.0.tgz
npm rm -g global-package

Details

npm-debug.log

0 info it worked if it ends with ok
1 verbose cli [ ‘/home/kristjan/n/bin/node’,
1 verbose cli ‘/home/kristjan/n/bin/npm’,
1 verbose cli ‘rm’,
1 verbose cli ‘-g’,
1 verbose cli ‘global-package’ ]
2 info using npm@6.9.0
3 info using node@v10.15.3
4 verbose npm-session 65da527f86379817
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 timing stage:loadCurrentTree Completed in 23ms
8 silly install loadIdealTree
9 silly install cloneCurrentTreeToIdealTree
10 timing stage:loadIdealTree:cloneCurrentTree Completed in 1ms
11 silly install loadShrinkwrap
12 timing stage:loadIdealTree:loadShrinkwrap Completed in 3ms
13 silly uninstall loadAllDepsIntoIdealTree
14 silly install loadAllDepsIntoIdealTree
15 silly fetchPackageMetaData error for global-package@file:…/…/tmp/global-package/global-package-1.0.0.tgz ENOENT: no such file or directory, stat ‘/home/kristjan/tmp/global-package/global-package-1.0.0.tgz’
16 timing stage:rollbackFailedOptional Completed in 0ms
17 timing stage:runTopLevelLifecycles Completed in 40ms
18 verbose stack Error: ENOENT: no such file or directory, stat ‘/home/kristjan/tmp/global-package/global-package-1.0.0.tgz’
19 verbose cwd /home/kristjan/tmp/global-package
20 verbose Linux 4.15.0-46-generic
21 verbose argv “/home/kristjan/n/bin/node” “/home/kristjan/n/bin/npm” “rm” “-g” “global-package”
22 verbose node v10.15.3
23 verbose npm v6.9.0
24 error path /home/kristjan/tmp/global-package/global-package-1.0.0.tgz
25 error code ENOENT
26 error errno -2
27 error syscall stat
28 error enoent ENOENT: no such file or directory, stat ‘/home/kristjan/tmp/global-package/global-package-1.0.0.tgz’
29 error enoent This is related to npm not being able to find a file.
30 verbose exit [ -2, true ]

Platform Info

$ npm --versions
{ npm: '6.9.0',
  ares: '1.15.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.15.3',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '6.8.275.32-node.51',
  zlib: '1.2.11' }
$ node -p process.platform
linux