Use of @ Symbol in Node Module Names

Use of @ symbol in Node module names

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.

Why do node modules have an `@` in the name?

@ indicates that the package is a scoped package. It is a way of grouping similar projects under single scope. A scoped package can be published as private as well as public. For more info check out the following link npm-scope

What is the meaning of the at (@) prefix on npm packages?

This is a new feature of NPM called 'scoped packages', which effectively allow NPM packages to be namespaced. Every user and organization on NPM has their own scope, and they are the only people who can add packages to it.

This is useful for several reasons:

  • It allows organizations to make it clear which packages are 'official' and which ones are not.

    • For example, if a package has the scope @angular, you know it was published by the Angular core team.
  • The package name only has to be unique to the scope it is published in, not the entire registry.

    • For example, the package name http is already taken in the main repository, but Angular is able to have @angular/http as well.

The reason that scoped packages don't show up in public search is because a lot of them are private packages created by organizations using NPM's paid services, and they're not comfortable opening the search up until they can be totally certain they're not going to make anything public that shouldn't be public - from a legal perspective, this is pretty understandable.

For more information, see the NPM docs and the Angular docs.

EDIT: It appears that public scoped packages now show up properly in search!

Why do some npm packages start with @?

If a package's name begins with @, then it is a scoped package. The scope is everything in between the @ and the slash

@scope/project-name

How to Initialize a Scoped Package

To create a scoped package, you simply use a package name that starts with your scope.

{
"name": "@username/project-name"
}

More details, Please visit scoped package

and

What does "@" symbol mean in "import { Component } from '@angular/core';" statement?

Using the ° symbol in Mongo model name

Plainly put, the degree symbol (°) is not valid in a variable name. Instead, consider naming your model mDegCelsius or something similar, which still portrays the same information in a reasonable (and valid) format.

What is the @ symbol meaning in require?

NPM allows users to organize packages into organization scopes.

The @google-cloud part is the scope and pubsub is the package name.

Organizing Packages docs explain it much better.

How to import modules with @ symbol in path in using nodejs?

Answer

I ended up using link-module-alias.

It creates a symlink for your alias and just like module-alias its defined in the same way inside package.json you add:

{
// ... details, dependencies etc.
"_moduleAliases": {
"@": "./src"
},
}

Possible answer

I saw that a possible solution exists using module-alias.
You would defined the exact same "_moduleAliases" as in the answer above in your package.json but instead of a symlink you would use module-alias at runtime like so:

node -r module-alias/register -r esm index.js 8081

But it did not work for me.

What does the ! character do in nodejs module names?

Short answer

It identifies a resource that is part of a plugin.

The structure of the identifier is: [plugin]![resource].

Long answer

In the documentation, you can find that:

Intern is built on top of a standard amd loader, which means that its modules are also normally written in the AMD module format.

That's why and how the require function is actually injected, so it's clear that you are not using the require module provided along with Node.JS.

It states also that:

[AMD format] Allows modules and other assets to be asynchronously or conditionally resolved by writing simple loader plugins

If you follow the link provided with the documentation when it cites the loaders, you find that:

Loader plugins extend an AMD implementation by allowing loading of resources that are not traditional JavaScript dependencies.

In particular, you can find that a dependency has the following form:

[Plugin Module ID]![resource ID]

It goes without saying that the default implementation of the loader you get by using intern adheres to the above mentioned standard.

That said, it follows that, if we consider:

intern/chai!assert

You can read it as inter/chai as plugin module and assert as actually required resource.

The purpose of the ! character in the argument of the require() method is to satisfy the requirements of the syntax used to identify a resource that is itself part of a plugin.

What does the @ symbol do in javascript imports?

The meaning and structure of the module identifier depends on the module loader or module bundler. The module loader is not part of the ECMAScript spec. From a JavaScript language perspective, the module identifier is completely opaque. So it really depends on which module loader/bundler you are using.

You most likely have something like babel-plugin-root-import in your webpack/babel config.

Basically it means from the root of the project.. it avoids having to write things like import Component from '../../../../components/component'

Edit: One reason it exists is because import Component from 'components/component' doesn't do that but instead search in the node_modules folder



Related Topics



Leave a reply



Submit