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
- nstd: Gives the same output as Node.js in side-by-side tests: esm.
- Browser: Loads with a minimal
processobject. 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,
undefinedthe other. - ❔
undefinedboth ways. - ❌ Not exported at all.
- – Not measured.
| Export | Node.js | Browser |
|---|---|---|
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 anode:vfsmount on four bindings diffed against the host's, and needsunsafe-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./distdoes not install, so it throwsERR_NSTDLIB_NO_MODULE_COMPILERunless a host installs one onnode_binding_module_wrap_compileSourceTextModule.native/drives QuickJS-NG's andnstdlib/esmexports one built on acorn.enableCompileCache()reports aFAILEDstatus rather than throwing, because there is no disk to cache to.runMainis 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 withnstdlib-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)