npm Community Forum (Archive)

The npm community forum has been discontinued.

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

npm uninstall fails when local file/folder doesn't exist

What I Wanted to Do

uninstall a dependency that no longer exists with npm uninstall some-package
assuming that there is a dependency in package.json such as "some-package": "file:../some-package" and that folder doesn’t exist

I’d expect the dependency to be removed from package.json

What Happened Instead

npm ERR! code ENOLOCAL
npm ERR! Could not install from "../some-package" as it does not contain a package.json file.

Reproduction Steps

npm init
manually add "some-package": "file:../some-package" to dependencies/devDependencies
npm uninstall some-package


Platform Info

$ npm --versions
{ 'test-npm': '1.0.0',
  npm: '6.4.1',
  ares: '1.10.1-DEV',
  cldr: '32.0',
  http_parser: '2.8.0',
  icu: '60.1',
  modules: '57',
  napi: '3',
  nghttp2: '1.33.0',
  node: '8.14.1',
  openssl: '1.0.2q',
  tz: '2017c',
  unicode: '10.0',
  uv: '1.23.2',
  v8: '6.2.414.75',
  zlib: '1.2.11' }
$ node -p process.platform

If I remember correctly, npm always looks for the manifest to build the dependency tree before doing any other step installing/uninstalling etc. I’ll take a look at if that can be avoided in any way.

Edit: thinking about it, you do want npm uninstall to look at the full tree, including the deps you want to uninstall, because you need to remove subdeps too. So npm can’t just not add those to the tree, the only thing I think it could do is to fall back on package-lock.json/node_modules/ if the manifest cannot be fetched. However that doesn’t sound great either, given it might silently fail to remove subdeps then, and people would probably be unhappy about that. sigh

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)