node:module

#Import

import module from "nstdlib/node/module";

Note

Behaviour verified against the host's own copy of three real npm packages, through both loaders. createRequire() resolves and runs CommonJS out of a node:vfs mount on four bindings diffed against the host's, and needs unsafe-eval. import() of CommonJS, JSON and registered builtins works over the same mount, and so does the whole ES module resolver. ES module source text needs a module compiler, which ./dist does not install, so it throws ERR_NSTDLIB_NO_MODULE_COMPILER unless a host installs one on node_binding_module_wrap_compileSourceTextModule. native/ drives QuickJS-NG's and nstdlib/esm exports one built on acorn. enableCompileCache() reports a FAILED status rather than throwing, because there is no disk to cache to. runMain is undefined.

#Support

node:module. nstd: works; Node test suite 70% passing. Browser: some support; export coverage 97%; Node test suite 46.9% passing.

  • nstd: Gives the same output as Node.js in side-by-side tests: esm.
  • Browser: Loads with a minimal process object. 32 of Node's 33 exports are available. 1 of 2 behavior checks match Node.js. Didn't match: import() of CommonJS and JSON out of the mount (a known difference).

#Exports (33)

Every name Node.js exports from this module, and what you get when you read it, as a named import or as a property of the default import:

  • ✅ A value, both ways. An export that throws an error naming the missing feature also counts.
  • ⚠️ A value one way, undefined the other.
  • ❔ undefined both ways.
  • ❌ Not exported at all.
  • – Not measured.
ExportNode.jsBrowser
Module✅✅
SourceMap✅✅
_cache✅✅
_extensions✅✅
_findPath✅✅
_initPaths✅✅
_load✅✅
_nodeModulePaths✅✅
_pathCache✅✅
_preloadModules✅✅
_readPackage✅✅
_resolveFilename✅✅
_resolveLookupPaths✅✅
_stat✅✅
builtinModules✅✅
constants✅✅
createRequire✅✅
enableCompileCache✅✅
findPackageJSON✅✅
findSourceMap✅✅
flushCompileCache✅✅
getCompileCacheDir✅✅
getSourceMapsSupport✅✅
globalPaths✅✅
isBuiltin✅✅
register✅✅
registerHooks✅✅
runMain✅❌
setSourceMapsSupport✅✅
stripTypeScriptTypes✅✅
syncBuiltinESMExports✅✅
wrap✅✅
wrapper✅✅

#Diagnostics

nstdlib running inside Node.js. This isn't an environment it's meant for, so it isn't shown above, but it tells a library problem from an environment one:

  • coverage: 32/33 of the host's export names answer inside host node. Behaviour verified against the host's own copy of three real npm packages, through both loaders. createRequire() resolves and runs CommonJS out of a node:vfs mount on four bindings diffed against the host's, and needs unsafe-eval. import() of CommonJS, JSON and registered builtins works over the same mount, and so does the whole ES module resolver. ES module source text needs a module compiler, which ./dist does not install, so it throws ERR_NSTDLIB_NO_MODULE_COMPILER unless a host installs one on node_binding_module_wrap_compileSourceTextModule. native/ drives QuickJS-NG's and nstdlib/esm exports one built on acorn. enableCompileCache() reports a FAILED status rather than throwing, because there is no disk to cache to. runMain is undefined.
  • smoke: Imports in a clean child process.
  • node-suite: 14/33 of Node's own eligible tests pass with ./dist inside host node. A failure there and in the page is the library's, one only in the page is the engine's.
  • wasm-differentials: Cjs_lexer: pass against the host's own builtin with nstdlib-wasm's blob installed. The published binding refuses without it. Cjs_lexer: merve agrees with Node across 11068 sources.

#Missing exports (1)

These exports exist in Node.js but are missing from nstdlib:

  • runMain (undefined)