Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

329
Visualizações
Nodejs require module starts with '#'

From Nodejs docs https://nodejs.org/api/modules.html#all-together

require(X) from module at path Y
1. If X is a core module,
   a. return the core module
   b. STOP
2. If X begins with '/'
   a. set Y to be the filesystem root
3. If X begins with './' or '/' or '../'
   a. LOAD_AS_FILE(Y + X)
   b. LOAD_AS_DIRECTORY(Y + X)
   c. THROW "not found"
4. If X begins with '#'
   a. LOAD_PACKAGE_IMPORTS(X, dirname(Y))
5. LOAD_PACKAGE_SELF(X, dirname(Y))
6. LOAD_NODE_MODULES(X, dirname(Y))
7. THROW "not found"

What does no.4 refer to?
What does it mean for a module to start with #?

LOAD_PACKAGE_IMPORTS(X, DIR)
1. Find the closest package scope SCOPE to DIR.
2. If no scope was found, return.
3. If the SCOPE/package.json "imports" is null or undefined, return.
4. let MATCH = PACKAGE_IMPORTS_RESOLVE(X, pathToFileURL(SCOPE),
  ["node", "require"]) defined in the ESM resolver.
5. RESOLVE_ESM_MATCH(MATCH).

This is the LOAD_PACKAGE_IMPORTS but it looks enigma to me.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The character "#" at the beginning of an import specifier refers to an imports field defined in package.json.

Imports fields are useful to alias file names or other dependencies that are only accessed inside a package.

Considering the example in the documentation:

  "imports": {
    "#dep": {
      "node": "dep-node-native",
      "default": "./dep-polyfill.js"
    }
  }

When a module in this package contains an import statement like

import dep from "#def";

This tells Node.js to import the package "dep-node-native"; and it instructs other build tools (for the browser) to use the local file "./dep-polyfill.js".

about 4 years ago · Juan Pablo Isaza Relatório

0

This is explained in https://nodejs.org/api/packages.html#subpath-imports:

Subpath imports

Added in: v14.6.0, v12.19.0

In addition to the "exports" field, it is possible to define internal package import maps that only apply to import specifiers from within the package itself.

Entries in the imports field must always start with # to ensure they are disambiguated from package specifiers.

(emphasis mine)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda