vm.SyntheticModule 类

此特性仅在启用 --experimental-vm-modules 命令标志时可用。

    Stability: 1 - Experimental

    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.

    const vm = require('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...