Use of @ symbol in Node module names [duplicate]

Solution 1:

Scoped packages in npm are preceded by an '@' symbol.

Scopes are a way of grouping related packages together, and also affect a few things about the way npm treats the package. Each npm user/organization has their own scope, and only you can add packages in your scope. This means you don’t have to worry about someone taking your package name ahead of you. Thus it is also a good way to signal official packages for organizations. https://docs.npmjs.com/misc/scope

A scope allows you to create a package with the same name as a package created by another user or Org without conflict. https://docs.npmjs.com/about-scopes

The docs include additional information on requiring scoped packages: https://docs.npmjs.com/misc/scope#requiring-scoped-packages

Requiring scoped packages

Because scoped packages are installed into a scope folder, you have to include the name of the scope when requiring them in your code, e.g.

require('@myorg/mypackage')

There is nothing special about the way Node treats scope folders, this is just specifying to require the module mypackage in the folder called @myorg.

Solution 2:

The @ scope is indicates common package ownership for a set of packages

From the official documentation is at: https://docs.npmjs.com/about-scopes

When you sign up for an npm user account or create an Org, you are granted a scope that matches your user or Org name. You can use this scope as a namespace for related packages.

A scope allows you to create a package with the same name as a package created by another user or Org without conflict.

The main advantage of scopes I've seen so far is that each scope is controlled by npm account of an organization / user, much like GitHub usernames / organization names.

This way, it makes it easy to determine if the package you are looking at belongs to an organization you trust, or if it is a third party tool.

For example, if you see a package:

@angular/cli

then you know that it comes from the user / group that controls the Angular team and can be trusted.

On the other hand, the same could not be said about:

angular-cli

TODO: the web UI / URL scheme is really wonky, how do you easily link: https://www.npmjs.com/package/@angular/cli to the corresponding organization / user page, presumably https://www.npmjs.com/~angular ? By searching the page source, the only hit for that URL is under "collaborators", but that contains other collaborators as well: https://www.npmjs.com/~angular-cli and https://www.npmjs.com/~google-wombot

See also: What is the meaning of the "at" (@) prefix on npm packages?

Solution 3:

So I solved this one myself.

Turns out @company/config is one of our private NPM repositories, hosted on npm and defined by this alias to an internal GitHub repository: it had nothing to do with how require works.

Using @ may or may not be a protocol that I was unaware of for private NPM repos, keep that in mind if you run into this.