NPM command confusion 

Intro 

Managing dependencies in JavaScript tasks can shortly change into a fancy endeavor. Duties embrace protecting monitor of variations, making certain compatibility, and dealing with updates . npm supplies a strong answer to those issues, by a centralized system for managing undertaking dependencies. Primarily accessed by its command-line interface (CLI), npm allows builders to seamlessly set up, handle, and share code dependencies. 

The story 

A couple of decade in the past, the npm CLI  added aliases to the instructions to scale back the time spent typing the closely used ones. For instance, “npm install” was shortened to “npm i”. This characteristic saved evolving, attempting so as to add all potential permutations and trying to catch typos: add-user for npm adduser, “instal” or “insta” for npm set up. 

When one more alias – “npm add” for npm set up – was added, everybody neglected the potential confusion with the prevailing “npm adduser” command (which already had the alias “add-user”).  

When fastidiously studying “npm adduser” and “npm add user”, we will clearly see the distinction, however once we swiftly kind it, the possibility of hitting a whitespace is extraordinarily excessive. 

Within the PR that added this new alias to the documentation, the consumer ahasall identified this subject, however their warning went unnoticed.  

The difficulty 

NPM has two instructions that look virtually similar however do fully various things: “npm add user” and “npm adduser”. 

NPN Docs screenshot

The “npm add example-package” command is an alias of “npm install” and easily installs the examplepackage package deal, whereas “npm adduser” creates a brand new consumer within the specified registry. 

Once you arrange the npm cli, you have to kind “npm adduser” to log into the registry. What’s the likelihood of typing “npm add user” as an alternative of “adduser”? Apparently, it’s very excessive. In keeping with npm-stat.com, downloads of the “user” package deal’ have risen dramatically, reaching almost 12 million in whole. 

screenshot showing packages download chart

Judging by the statistics, many builders have made this typo and inadvertently put in the package deal. NPM studies that there are 2760 dependent packages, a minimum of 20 of which had been added in December 2024. 

NPM 2760 dependent packages

Presently the package deal itself is benign and is solely a hello-world app. Nonetheless, future variations of it might probably comprise malicious code, resulting in an infection of the unsuspecting victims who will make this typing error.  

Due to this fact, whereas whoever has the present benign model of their package deal.json is secure,  those that improve or set up it for the primary time could possibly be uncovered to malware.  

Conclusion 

Device designers should fastidiously take into account all present instructions to stop any potential confusion between them. 

The package deal stays a ticking bomb for the hundreds of builders who inadvertently put in it. 

The difficulty has been reported to npm; the put up might be up to date with the response. 

Recent articles