Optional
mocker: Mockertrue
if the module is running during the Node.js preload
v11.14.0
The directory name of the module. This is usually the same as the path.dirname() of the module.id.
Static
ModuleStatic
SourceStatic
_cacheStatic
builtinStatic
findStatic
syncThe 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
.
const fs = require('node:fs');
const assert = require('node:assert');
const { syncBuiltinESMExports } = require('node:module');
fs.readFile = newAPI;
delete fs.readFileSync;
function newAPI() {
// ...
}
fs.newAPI = newAPI;
syncBuiltinESMExports();
import('node:fs').then((esmFS) => {
// It syncs the existing readFile property with the new value
assert.strictEqual(esmFS.readFile, newAPI);
// readFileSync has been deleted from the required fs
assert.strictEqual('readFileSync' in fs, false);
// syncBuiltinESMExports() does not remove readFileSync from esmFS
assert.strictEqual('readFileSync' in esmFS, true);
// syncBuiltinESMExports() does not add names
assert.strictEqual(esmFS.newAPI, undefined);
});
Static
createStatic
isStatic
registerOptional
parentURL: string | URLOptional
options: RegisterOptions<Data>Optional
options: RegisterOptions<Data>Static
runStatic
wrap
A child class of Module, which loads modules from the mock object if specified, otherwise will load unmocked modules in its own mocked environment, so that they will load the mocked modules as well.