`node:module` API
目录
自 v12.20.0 版本开始新增
自 v0.3.7 版本开始新增
The Module
object
Provides general utility methods when interacting with instances of
Module
, the module
variable often seen in CommonJS modules. Accessed
via import 'node:module'
or require('node:module')
.
M module.builtinModules
自 v9.3.0, v8.10.0, v6.13.0 版本开始新增
- string[]
A list of the names of all modules provided by Node.js. Can be used to verify if a module is maintained by a third party or not.
module
in this context isn't the same object that's provided
by the module wrapper. To access it, require the Module
module:
MJS
CJS
M module.createRequire(filename)
自 v12.2.0 版本开始新增
filename
string
|URL
Filename to be used to construct the require function. Must be a file URL object, file URL string, or absolute path string.- Returns:
require
Require function
MJS
M module.isBuiltin(moduleName)
自 v18.6.0 版本开始新增
moduleName
string
name of the module- Returns:
boolean
returns true if the module is builtin else returns false
MJS
M module.syncBuiltinESMExports()
自 v12.12.0 版本开始新增
The module.syncBuiltinESMExports()
method updates all the live bindings for
builtin ES Modules to match the properties of the CommonJS exports. It
does not add or remove exported names from the ES Modules.
JS
Source map v3 support
自 v13.7.0, v12.17.0 版本开始新增
Helpers for interacting with the source map cache. This cache is populated when source map parsing is enabled and source map include directives are found in a modules' footer.
To enable source map parsing, Node.js must be run with the flag
--enable-source-maps
, or with code coverage enabled by setting
NODE_V8_COVERAGE=dir
.
MJS
CJS
M module.findSourceMap(path)
自 v13.7.0, v12.17.0 版本开始新增
path
string
- Returns:
module.SourceMap
|undefined
Returnsmodule.SourceMap
if a source map is found,undefined
otherwise.
path
is the resolved path for the file for which a corresponding source map
should be fetched.
C module.SourceMap
自 v13.7.0, v12.17.0 版本开始新增
M new SourceMap(payload)
payload
Object
Creates a new sourceMap
instance.
payload
is an object with keys matching the Source map v3 format:
file
:string
version
:number
sources
: string[]sourcesContent
: string[]names
: string[]mappings
:string
sourceRoot
:string
M sourceMap.payload
- Returns:
Object
Getter for the payload used to construct the SourceMap
instance.
M sourceMap.findEntry(lineNumber, columnNumber)
Given a line number and column number in the generated source file, returns an object representing the position in the original file. The object returned consists of the following keys: