Cannot return value from a SourceTextModule to the caller

  • Version: v15.9.0
  • Platform: macOS Catalina 10.15.6
  • Subsystem: VM

What steps will reproduce the bug?

Make file retu.js.

const vm = require('vm');
const contextifiedSandbox = vm.createContext({ });
(async () => {
  const bar = new vm.SourceTextModule(`19;`, { context: contextifiedSandbox });
  async function linker(specifier, referencingModule) { }
  await bar.link(linker);
  const  result  = await bar.evaluate();
  console.log("Result is: ", result);
})();

Run as node --experimental.vm.modules retu.js

What is the expected behavior?

According to the current state of the documentation I expect an output of Result is: 19

What do you see instead?

Output of: Result is: undefined

1 possible answer(s) on “Cannot return value from a SourceTextModule to the caller

  1. @clecap the default export is available via module.namespace.default, though it would be undefined in your example. There is no way to access the “last evaluated expression” as there is with vm.Script.