Trying the new SourceTextModule API, I'm trying to extract my exports.
Here's what I've got:
async function loader() {
    // ...
    const context = vm.createContext({
        require: filename => {
            return filename;
        },
        module: {
            exports: {},
        }
    });
    const mod = new vm.SourceTextModule(source, {
        context,
        identifier: module.identifier(),
    });
    async function linker(specifier, referencingModule) {
        throw new Error(`Unable to resolve dependency: ${specifier}`);
    }
    await mod.link(linker);
    const result = await mod.evaluate();
    console.log("RESULT", result);
}
Where source is:
var manifest = {
  name: "MyApp",
  // ...
};
export default manifest;
This is printing
RESULT [Object: null prototype] { result: undefined }
How can I get access to that export default? i.e., I want that manifest object.
You can use mod.namespace....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With