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"
node-compat (enabled by default; disable with --no-node-compat)Example
Section titled “Example”import { builtinModules, isBuiltin } from "node:module";
console.log(isBuiltin("node:fs"));console.log(builtinModules.includes("fs"));createRequirev0.0.0-alpha.2findPackageJSONv0.0.0-alpha.2package.json file starting from specifier.isBuiltinv0.0.0-alpha.2true if moduleName names a built-in module (with or without "node:").syncBuiltinESMExportsv0.0.0-alpha.2Functions
Section titled “Functions”createRequire
Section titled “createRequire”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".
| Name | Type | Description |
|---|---|---|
filename | string | import("node:url").URL | File path or file:// URL used as the resolution anchor. |
never — Never returns.Error— Always throws withcode = "ERR_UNSUPPORTED".
findPackageJSON
Section titled “findPackageJSON”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.
| Name | Type | Description |
|---|---|---|
specifier | string | import("node:url").URL | Starting file path, directory path, or file:// URL. |
base optional | string | import("node:url").URL | Optional base path or URL when specifier is a package name. |
string | undefined — Path to the nearest package.json, or undefined if none is found.isBuiltin
Section titled “isBuiltin”export function isBuiltin(moduleName: string): boolean;
Return true if moduleName names a built-in module (with or without "node:").
| Name | Type | Description |
|---|---|---|
moduleName | string | Module specifier to test. |
boolean — true if built-in, otherwise false.syncBuiltinESMExports
Section titled “syncBuiltinESMExports”export function syncBuiltinESMExports(): void;
Synchronize live bindings between ESM and CommonJS views of built-in modules.
voidInterfaces
Section titled “Interfaces”RequireResolve
Section titled “RequireResolve”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().
(request: string, options?: { paths?: string[] }): string;
Resolve a module specifier relative to the base path of createRequire().
| Name | Type | Description |
|---|---|---|
request | string | Module specifier or relative path. |
options optional | { paths?: string[] } | Optional search path overrides. |
string — Resolved filesystem path or built-in specifier.RequireResolve.paths
Section titled “RequireResolve.paths”paths(request: string): string[] | null;
Return candidate search directories for resolving request, or null
when request is a core module.
| Name | Type | Description |
|---|---|---|
request | string | Module specifier. |
string[] | null — Array of lookup paths, or null.NodeRequire
Section titled “NodeRequire”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".
(id: string): never;
Always throws ERR_UNSUPPORTED because CommonJS loading is not supported in VaelJS.
| Name | Type | Description |
|---|---|---|
id | string | Module specifier or path. |
neverTypeError— withcode = "ERR_UNSUPPORTED".
| Property | Type | Description | Since |
|---|---|---|---|
resolve | RequireResolve | Module path resolver (throws ERR_UNSUPPORTED when invoked). | v0.0.0-alpha.2 |
cache readonly | Record<string, unknown> | Empty read-only placeholder cache map. | v0.0.0-alpha.2 |
extensions readonly | Record<string, unknown> | Empty read-only extension handler map. | v0.0.0-alpha.2 |
main readonly | unknown | Always undefined (ESM runtime). | v0.0.0-alpha.2 |
Constants
Section titled “Constants”builtinModules
Section titled “builtinModules”export const builtinModules: readonly string[];
List of bare Node built-in module names supported by this runtime.
Default Export
Section titled “Default Export”default export
Section titled “default export”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.
