SyntheticModule
This feature is only available with the --experimental-vm-modules command flag enabled.
The vm.SyntheticModule class provides the Synthetic Module Record as defined in the WebIDL specification. The purpose of synthetic modules is to provide a generic interface for exposing non-JavaScript sources to ECMAScript module graphs.
import vm from 'node:vm';
const source = '{ "a": 1 }';
const module = new vm.SyntheticModule(['default'], function() {
const obj = JSON.parse(source);
this.setExport('default', obj);
});
// Use `module` in linking...Content copied to clipboard
Since
v13.0.0, v12.16.0
Constructors
Link copied to clipboard
constructor(exportNames: ERROR CLASS: Symbol not found for js.array.ReadonlyArray<kotlin/String>, evaluateCallback: () -> Unit, options: SyntheticModuleOptions = definedExternally)
Creates a new SyntheticModule instance.
Properties
Functions
Link copied to clipboard
suspend fun evaluate(options: ModuleEvaluateOptions = definedExternally): ERROR CLASS: Symbol not found for js.core.Void
Link copied to clipboard
fun evaluateAsync(options: ModuleEvaluateOptions = definedExternally): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for js.core.Void>
Evaluate the module.
Link copied to clipboard
Link copied to clipboard
fun linkAsync(linker: ModuleLinker): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for js.core.Void>
Link module dependencies. This method must be called before evaluation, and can only be called once per module.