SyntheticModule
[<Interface>]
type SyntheticModule =
static member Create (setExport: Action<string,obj>, error: obj, identifier: string, context: Context, namespace: Object, status: ModuleStatus, evaluate: ModuleEvaluateOptions option -> Promise<unit>, link: ModuleLinker -> Promise<unit>) : SyntheticModule
abstract member setExport (name: string, value: obj) : unit| Assembly | Xantham.Fable.Node |
| Implements | Module |
| Attributes | [<Interface>] |
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...
@since v13.0.0, v12.16.0
Methods
static member Create (setExport: Action<string,obj>, error: obj, identifier: string, context: Context, namespace: Object, status: ModuleStatus, evaluate: ModuleEvaluateOptions option -> Promise<unit>, link: ModuleLinker -> Promise<unit>) : SyntheticModuleabstract member setExport (name: string, value: obj) : unit
abstract member setExport (name: string, value: obj) : unitThis method is used after the module is linked to set the values of exports. If it is called before the module is linked, an ERR_VM_MODULE_STATUS error will be thrown.
import vm from 'node:vm';
const m = new vm.SyntheticModule(['x'], () => {
m.setExport('x', 1);
});
await m.link(() => {});
await m.evaluate();
assert.strictEqual(m.namespace.x, 1);
@since v13.0.0, v12.16.0
| Parameter | |
|---|---|
name | Name of the export to set. |
value | The value to set the export to. |