Skip to content

node:module

How Elide supports Node's module helpers: createRequire, isBuiltin and builtinModules, with source-map lookups stubbed and loader hooks unsupported.

On this page

node:module exports createRequire, isBuiltin, builtinModules, and the rest of Node’s module helpers.

Example

js
// module.mjs
import { builtinModules, createRequire, isBuiltin } from "node:module";

const require = createRequire(import.meta.url);
const { basename } = require("node:path");
console.log(basename("/srv/app/main.js"));
console.log(isBuiltin("node:fs"), isBuiltin("fs/promises"), isBuiltin("left-pad"));
console.log(builtinModules.includes("worker_threads"));
utf-8 · js · Lines: 8

elide run module.mjs prints:

text
main.js
true true false
true
utf-8 · text · Lines: 3

Differences from Node

  • createRequire returns the realm’s require; relative paths do not resolve against the filename passed to it.
  • syncBuiltinESMExports() is a no-op.
  • findSourceMap() returns undefined; getSourceMapsSupport() reports source maps disabled.
  • Loader customization hooks (register) are not supported.
  • require.resolve() returns the specifier unchanged for built-ins.

Reference

Status: Partial · 45 of 52 suite tests pass (86.5%)

module exports

Module, builtinModules, createRequire, findSourceMap, getSourceMapsSupport, globalPaths, isBuiltin, runMain, setSourceMapsSupport, syncBuiltinESMExports, wrap, wrapper

Not implemented

SourceMap, constants, enableCompileCache, findPackageJSON, flushCompileCache, getCompileCacheDir, register, registerHooks, stripTypeScriptTypes.

Tests: node-api node:module-loading: 45 pass, 7 fail, 0 error, 5 skipped. Failing: test-module-loading-globalpaths.js, test-module-main-fail.js, test-module-main-preserve-symlinks-fail.js, test-module-prototype-mutation.js, test-module-run-main-monkey-patch.js, test-require-package-map.js, test-require-symlink.js.

Was this page helpful?