Index of every page on this site: llms.txt
All skills
jasnell avatar

/node-modules-loading

@5f83e6c
Run it yourself

Node.js now runs TypeScript .ts files directly (type stripping is Stable) and loads code differently: require() of ES modules, loader hooks with module.registerHooks (which replaces module.register and --loader), package maps and the compile cache. Use when running TypeScript without a build step or instead of tsx/ts-node, requiring ESM from CommonJS, writing or migrating loader hooks, fixing "bad option: --loader", resolving packages in a monorepo, or using --config-file. Covers --no-strip-types, ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX, ERR_REQUIRE_ASYNC_MODULE, import with type 'text', Wasm import source, the "worker" condition, "private" packages and the compile cache. Node.js 24+.

Use this Skill: https://skilld.dev/gh/jasnell/node-skills/node-modules-loading

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

rulespackage-maps.md

≈704 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Package maps (--experimental-package-map)

Source: doc/api/packages.md (Package maps), cli.md, errors.md. Added v26.4.0, v24.20.0, so it is not on v24.19.0 or v25.x. Stability 1 (Experimental).

node --experimental-package-map=./package-map.json app.js

Package maps resolve bare specifiers from a static JSON file instead of walking node_modules. They fit monorepos without symlinks or hoisting, blocking phantom (undeclared) dependencies, and resolution with no filesystem probing.

Format

{
  "packages": {
    "app":   { "url": "./packages/app",   "dependencies": { "@my/utils": "utils" } },
    "utils": { "url": "./packages/utils" }
  }
}
  • Each key in packages is a package ID.
  • url (required): a file: URL or a relative path, resolved against the map file's URL. It points at the package directory.
  • dependencies: maps a bare specifier (as written in source) to a package ID. The default is {}.
  • Different packages may map the same specifier to different IDs, which allows several versions side by side.
  • Do not give two IDs the same url. packages.md says this is allowed ("Multiple packages for the same URL"). In practice, on v26.13.0 and main, the whole map is rejected with ERR_PACKAGE_MAP_INVALID ("packages "a" and "b" have the same url"), which is what errors.md documents. To get two dependency sets, use two directories.

Resolution

  1. Find the importing package: the given package ID, or else the mapped url that contains the importing file.
  2. If the importing file is in no mapped package: ERR_PACKAGE_MAP_EXTERNAL_FILE.
  3. Look up the specifier's package name in that package's dependencies. If it is missing, the result is "not found" (verified: ERR_MODULE_NOT_FOUND from import), even if the target is in the map.
  4. Hand the package directory to normal resolution (exports, main, index.js).

The map does not affect relative or absolute specifiers or node: builtins.

Verified on v26.13.0 and main (examples/package-map.mjs): a declared dependency resolves through exports, an undeclared one fails, relative imports are untouched, and a file outside every package gets ERR_PACKAGE_MAP_EXTERNAL_FILE.

Errors

Code Cause
ERR_PACKAGE_MAP_EXTERNAL_FILE the importing file is outside every mapped package
ERR_PACKAGE_MAP_INVALID missing file, bad JSON, no packages, an entry without url, or two entries with the same url (missing file, missing url and duplicate url verified)
ERR_PACKAGE_MAP_KEY_NOT_FOUND a dependencies value names a package ID not in packages (verified)

Limits

The map is a single static file, read synchronously at startup. No dynamic configuration. No cycle detection.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts5d3 checks · Risk SAFE
  • Gen Agent Trust Hub5d

    This skill provides technical documentation and examples for modern Node.js module loading features. It includes scripts to verify feature behavior and contains no malicious patterns.

  • Socket5d

    No alerts

  • Snyk5d

    Risk: LOW · No issues

Signed by skilld at 5f83e6c. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 5 days ago.

Activeupdated last week

README badge

README badge for jasnell/node-skills/node-modules-loading