Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

323
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!