node:module
#Import
import module from "nstdlib/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 no JavaScript API exposes, so it throws ERR_NSTDLIB_NO_MODULE_COMPILER unless a host installs one on node_binding_module_wrap_compileSourceTextModule, which native/ does. enableCompileCache() reports a FAILED status rather than throwing, because there is no disk to cache to. runMain is undefined.
#Runtime support
| Where it runs | Status | Export coverage | Details |
|---|---|---|---|
| nstd | ✅ works | – | Native tests match Node.js: esm. |
| Browser | ⚠️ some support | 97% of Node.js | It imports with the small process shim. 32/33 Node.js exports are available. No module-specific behavior test ran. |
| Node.js (host) | ✅ works | 97% of Node.js | 32/33 exports. |
#Exports (32 of 33)
Each cell shows what happens when code reads an export:
- ✅ Available through every import style. A named error also counts.
- ⚠️ Available through only some import styles.
- ❔ The export exists but has no value.
- ❌ The export does not exist.
- – This environment was not measured.
| Export | Node.js | nstdlib | 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 | ✅ | ✅ | ✅ |
#Missing exports (1)
These exports exist in Node.js but not in nstdlib:
runMain (undefined)