Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

331
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda