Skip to content
VaelJS Blog

ESM & npm Resolution

This document captures the resolution contract behind vaeljs-npm and vaeljs-remote in vjs (v0.0.0-alpha.0) and vjs-lite (0.0.0-alpha.1), explaining why VaelJS resolves npm: packages without node_modules, lifecycle scripts, or CommonJS.

Three capabilities are kept strictly separate so enabling one does not silently pull in the others:

  1. ESM npm: packages (vaeljs-npm): Resolution, verified CAS extraction, and execution of strict ESM package graphs.
  2. node:* compatibility (vaeljs-node-core): Separately opt-outable (--no-node-compat) Node.js compatibility modules (39 modules in vjs / 27 synchronous/pure-JS modules in vjs-lite in v0.0.0-alpha.3, including node:fs, node:child_process, node:crypto, node:buffer, node:os, node:path, node:process, node:url, and more; see Node Compatibility Matrix).
  3. Project package.json & vael.jsonc: Local projects can consume package.json dependencies and #imports alongside vael.jsonc imports and workspaces, without creating a node_modules tree.

Deliberate non-goals (fail closed):

  • No CommonJS: .cjs, .cts, require(), createRequire(), and "type": "commonjs" .js files are rejected rather than wrapped or auto-converted.
  • No lifecycle scripts or native addons: preinstall, install, postinstall, and prepare scripts never run; .node, .dll, .so, .so.*, .dylib, .exe, and .wasm binaries are excluded from CAS extraction.
  • No node_modules directory: Packages live exclusively in the verified content-addressed store.
  1. Canonical scheme separation:
    • Bare names ("fs", "lodash") belong to vael.jsonc imports, package.json dependencies/#imports, or workspace packages — never to vael:* or node:* built-ins.
    • Built-ins require canonical vael:* or node:* specifiers.
    • npm:name@range/subpath and npm:@scope/name@range/subpath resolve via exact versions, npm semver ranges, or dist-tags.
  2. Peer-aware graph identity:
    • Bare imports inside a package resolve strictly against that package’s declared dependency graph (never a global latest fallback).
    • Module instances are keyed by graph-instance identity (including resolved peer bindings) and canonical module path so one package artifact bound to two different peers never shares mutable module state.
  3. Conditional exports & #imports:
    • Active resolution conditions are ["import", "default"] in manifest key order (node, node-addons, require, browser, and types are not claimed).
    • Rejected exports targets never fall back to main or arbitrary deep file paths.
  4. Strict ESM classification:
    • .mjs is always ESM; .js inside an npm package requires "type": "module" in its nearest package.json; .ts/.mts use erasable TypeScript stripping when permitted.

Content-Addressed Store ($XDG_CACHE_HOME/vaeljs/packages)

Section titled “Content-Addressed Store ($XDG_CACHE_HOME/vaeljs/packages)”
  • On Linux, cached artifacts live under $XDG_CACHE_HOME/vaeljs/packages (defaulting to $HOME/.cache/vaeljs/packages); Windows uses %USERPROFILE%\.cache\vaeljs\packages.
  • Tarballs are verified against sha512 SRI digests before atomic extraction into a private temporary directory (rejecting traversal, unsafe links, device files, and native addons).
  • Extracted files are stored read-only (0444 on Unix) keyed by SHA-256. Every read verifies O_NOFOLLOW, exact byte length, and in-memory SHA-256 so tampering with extracted cache files is caught before execution even in --offline mode.
  • Records requested specifiers ("pkg@^1.0.0"), resolved package keys ("pkg@1.2.3"), versions, integrity digests, mandatory treeSha256 (fail-closed if missing on a pinned entry), tarballUrl, and dependency edges in canonical sorted JSON (max 16 MiB).
  • --frozen-lockfile fails on missing, stale, or mismatched entries without network mutation.
  • --offline forbids all network I/O and serves strictly from vael.lock and the verified CAS cache.
  • --no-npm disables npm: and package.json resolution entirely.
  • Network fetches are off by default in both vjs and vjs-lite and require --allow-remote or VAELJS_ALLOW_REMOTE=1 (overridable via --no-allow-remote).
  • .npmrc discovery is bounded (256 KiB, O_NOFOLLOW on Unix) and HTTPS-only. Project-local .npmrc is restricted to non-secret registry routing (registry=, @scope:registry=) and rejects auth directives (_authToken, _auth, username, _password, always-auth, //host:) and ${ENV_VAR} expansion (ProjectAuthNotAllowed); credentials and lazy ${ENV_VAR} interpolation belong strictly in user-level ~/.npmrc, where tokens are stored with ZeroizeOnDrop, redacted as <redacted>, and stripped on cross-origin redirects.
  • --allow-remote enables network module loading while vaeljs-remote enforces SSRF protection (allow_private_ips: false by default — blocking loopback, RFC 1918, link-local, metadata 169.254.169.254, CGNAT, ULA, and IPv4-mapped/NAT64 ranges at URL and DNS resolution levels). Note that --allow-remote is still not a host allowlist or OS sandbox: loaded modules retain host process capabilities.

npm:, jsr:, and gh: support in vjs and vjs-lite establishes the CAS + integrity foundation. Future private and self-hosted registry support via Vaelhoard (vael:@, jsr:@, npm:, OCI, and binary release artifacts) is tracked on the Public Roadmap and remains gated on Vaelspire and Vaelguard.