Not Found: -@latest error (nonsense error message)

What I Wanted to Do

If I would attempt to install a nonsense package name, as in the following command:

npm i - npm

I think the error message should clearly indicate that it was some kind of a syntax error.

What Happened Instead

I got the following output instead:

npm ERR! code E404
npm ERR! 404 Not Found: -@latest

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/brodybits/.npm/_logs/2019-02-01T18_32_06_552Z-debug.log

Reproduction Steps

Try entering the following command as given in What I Wanted to Do:

npm i - npm


I think it is evident that I really wanted to do npm i -g npm but missed the g character.

Platform Info

$ npm --versions
{ npm: '6.4.1',
  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.1',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '',
  zlib: '1.2.11' }
$ node -p process.platform

It looks like when passing null to the flag operand (-), it takes that as the package name and ignores anything after it. I haven’t extensively tested it, nor do I think it needs to be.

I suppose it’d be nice to have some argument suggestions when passing a null flag, but you already solved the bug yourself by stating that you already knew you had missed the “g” argument.

If someone were to work on this I’d mark it as low priority.

Some background detail.

It is up to each program how to process a lone dash. Most programs do not treat is as special and process it as an argument (like npm), and some treat it as a special character meaning to use stdin/stdout instead of their default behaviour (like cat and tar). I have not seen a program which treats it as a mistyped option, although I expect that is a common mistake in practice!

For example ls and git behave like npm and process the dash as a plain argument:

$ ls - npm
ls: -: No such file or directory
ls: npm: No such file or directory
$ git clone - npm
fatal: repository '-' does not exist

So the error message you see is from attempting to install a package named -. The error message has actually been improved in the current version of npm and it is clearer what npm has attempted:

$ npm install -
npm ERR! code E404
npm ERR! 404 Not Found - GET - Not found
npm ERR! 404 
npm ERR! 404  '-@latest' is not in the npm registry.
1 Like

I could make a PR to add a warning for this in nopt (the npm option parsing package) here, but I don’t know if any other npm commands use a single dash as a special argument.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.