24

When you type an illegal npm command, you are getting a user-friendly error message stating which commands are legal to use:

$ npm illegal

Usage: npm <command>

where <command> is one of:
    add-user, adduser, apihelp, author, bin, bugs, c, cache,
    completion, config, ddp, dedupe, deprecate, docs, edit,
    explore, faq, find, find-dupes, get, help, help-search,
    home, i, info, init, install, isntall, issues, la, link,
    list, ll, ln, login, ls, outdated, owner, pack, prefix,
    prune, publish, r, rb, rebuild, remove, repo, restart, rm,
    root, run-script, s, se, search, set, show, shrinkwrap,
    star, stars, start, stop, submodule, tag, test, tst, un,
    uninstall, unlink, unpublish, unstar, up, update, v,
    version, view, whoami

As you may notice, among others there is isntall command.

What is the point of this command? If this was created to handle typos, then why doesn't it have a special handling for intall, insatll etc? Besides, uninstall doesn't have a corresponding unisntall option.

(Using npm 1.3.22 version).


The reason I ask is that I'm a bit surprised and confused about how the typo is handled. For example, git compares the command you've entered and suggests the closest commands it has available:

$ git stats
git: 'stats' is not a git command. See 'git --help'.

Did you mean this?
    status

Also, pip Python package manager has a similar functionality built-in:

$ pip isntall
ERROR: unknown command "isntall" - maybe you meant "install"

FYI, under-the-hood it uses difflib.get_close_matches() function.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • 10
    It's to remind you that npm isntall that. – hobbs Nov 18 '14 at 05:31
  • 2
    OP, you should google your questions. This was my first result on the keyword 'isntall', from npm's github page. https://github.com/npm/npm/issues/2933 – James G. Nov 18 '14 at 05:31
  • 4
    Fun fact: the newest version of npm still accepts `isntall` as an alias, but it doesn't show it on that list anymore as to not confuse people. Personally I think having such an alias is just plain silly, but judging by the Github issue, they don't want any more feedback on that. – Matti Virkkunen Nov 18 '14 at 05:34
  • 3
    @alecxe: I guess with your rep you already know that "*What do you think?*"-questions are offtopic? You might bring up such things in chat. – Bergi Nov 18 '14 at 05:36
  • 1
    this totally weirded me out today – Oliver Watkins Sep 20 '16 at 13:43
  • 2
    this probably saved millions of hours worldwide, and then wasted it back by people starting to research that anomaly and writing comments like this one – Pawel Oct 20 '20 at 17:27

2 Answers2

24

I was the original "raiser" of the connected issue on Github, and those were the first days of contributing to OSS software... I thought it was just a typo, and maybe a pull request would solve it. But I was blessed with some good sense to first raise an issue (#2933) to find out if they were looking for contribution on that front...

As it turned out, it unravelled a whole discussion around the issue, which was good to see.

The raison d'être of the isntall command is because the npm maintainers believe that it saves them time — and thus, by extension — several other developers. As has been discussed in the linked issue, this was a contentious decision, and several people have suggested more interesting methods for resolving typos such as using the levenshtein distance calculation of the illegal command from valid npm commands (https://www.npmjs.org/package/levenshtein).

At any rate, I presume if you do implement one of those algos and contribute to the npm project, it would be a nice addition to this awesome library...

kumarharsh
  • 18,961
  • 8
  • 72
  • 100
1

Because there's no way to handle every single possible typo, without breaking other stuff. Init could possibly be a typo of install.

Could do levenshtein distance from your input or something but introduces unnecessary complexity.

BMC
  • 166
  • 4
  • `isntall` is actually hardcoded. It's such a common mistake that it became part of npm. it's not calculated based on small mistake – Pawel Dec 23 '16 at 10:30