Skip to content
VaelJS Blog

node:module

Node-compatible module metadata and CommonJS loader helpers (node:module).

Available in both vjs and vjs-lite runtimes. Enabled by default unless --no-node-compat is passed.

import ... from "node:module"
Since v0.0.0-alpha.2 vjs (V8) vjs-lite (QuickJS)
Cargo feature: node-compat (enabled by default; disable with --no-node-compat)
import { builtinModules, isBuiltin } from "node:module";
console.log(isBuiltin("node:fs"));
console.log(builtinModules.includes("fs"));
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function createRequire(filename: string | import("node:url").URL): never;

Unsupported CommonJS loader stub (Zero-CJS).

VaelJS is strictly ESM-only without CommonJS loading: calling createRequire() always throws an Error with code = "ERR_UNSUPPORTED".

Parameters
NameTypeDescription
filenamestring | import("node:url").URLFile path or file:// URL used as the resolution anchor.
Returns
never — Never returns.
Exceptions
  • Error — Always throws with code = "ERR_UNSUPPORTED".
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function findPackageJSON(
  specifier: string | import("node:url").URL,
  base?: string | import("node:url").URL,
): string | undefined;

Locate the nearest package.json file starting from specifier.

Parameters
NameTypeDescription
specifierstring | import("node:url").URLStarting file path, directory path, or file:// URL.
base optionalstring | import("node:url").URLOptional base path or URL when specifier is a package name.
Returns
string | undefined — Path to the nearest package.json, or undefined if none is found.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function isBuiltin(moduleName: string): boolean;

Return true if moduleName names a built-in module (with or without "node:").

Parameters
NameTypeDescription
moduleNamestringModule specifier to test.
Returns
boolean — true if built-in, otherwise false.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function syncBuiltinESMExports(): void;

Synchronize live bindings between ESM and CommonJS views of built-in modules.

Returns
void
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
export interface RequireResolve {
  (request: string, options?: { paths?: string[] }): string;
  paths(request: string): string[] | null;
}

Resolution function attached as .resolve on the loader returned by createRequire().

Call Signature
(request: string, options?: { paths?: string[] }): string;

Resolve a module specifier relative to the base path of createRequire().

Parameters
NameTypeDescription
requeststringModule specifier or relative path.
options optional{ paths?: string[] }Optional search path overrides.
Returns
string — Resolved filesystem path or built-in specifier.
Methods
methodSince v0.0.0-alpha.2
paths(request: string): string[] | null;

Return candidate search directories for resolving request, or null when request is a core module.

Parameters
NameTypeDescription
requeststringModule specifier.
Returns
string[] | null — Array of lookup paths, or null.
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
export interface NodeRequire {
  (id: string): never;
  resolve: RequireResolve;
  readonly cache: Record<string, unknown>;
  readonly extensions: Record<string, unknown>;
  readonly main: unknown;
}

CommonJS stub loader returned by createRequire().

VaelJS is ESM-only (Zero-CJS): invoking the returned function or .resolve() throws TypeError with code = "ERR_UNSUPPORTED".

Call Signature
(id: string): never;

Always throws ERR_UNSUPPORTED because CommonJS loading is not supported in VaelJS.

Parameters
NameTypeDescription
idstringModule specifier or path.
Returns
never
Exceptions
  • TypeError — with code = "ERR_UNSUPPORTED".
Properties
PropertyTypeDescriptionSince
resolve RequireResolveModule path resolver (throws ERR_UNSUPPORTED when invoked).v0.0.0-alpha.2
cache readonlyRecord<string, unknown>Empty read-only placeholder cache map.v0.0.0-alpha.2
extensions readonlyRecord<string, unknown>Empty read-only extension handler map.v0.0.0-alpha.2
main readonlyunknownAlways undefined (ESM runtime).v0.0.0-alpha.2
constSince v0.0.0-alpha.2vjs & vjs-lite
export const builtinModules: readonly string[];

List of bare Node built-in module names supported by this runtime.

defaultSince v0.0.0-alpha.2vjs & vjs-lite
const _default: {
  /** Built-in module name list. @since 0.0.0-alpha.2 */
  readonly builtinModules: readonly string[];
  /** Create a CommonJS loader anchored at `filename`. @since 0.0.0-alpha.2 */
  createRequire: typeof createRequire;
  /** Locate the nearest `package.json`. @since 0.0.0-alpha.2 */
  findPackageJSON: typeof findPackageJSON;
  /** Test whether a specifier refers to a built-in module. @since 0.0.0-alpha.2 */
  isBuiltin: typeof isBuiltin;
  /** Sync ESM/CJS built-in exports. @since 0.0.0-alpha.2 */
  syncBuiltinESMExports: typeof syncBuiltinESMExports;
};
export default _default;

Default export object providing the node:module API.