Stability: 1 - Experimental

    This feature is only available with the --experimental-vm-modules command flag enabled.

    • 继承自: {vm.Module}

    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.

    1. const vm = require('vm');
    2. const source = '{ "a": 1 }';
    3. const module = new vm.SyntheticModule(['default'], function() {
    4. const obj = JSON.parse(source);
    5. this.setExport('default', obj);
    6. });
    7. // Use `module` in linking...