Open
Description
Version
v18.4.0
Platform
Linux arch-linux 5.18.8-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Wed, 29 Jun 2022 23:03:10 +0000 x86_64 GNU/Linux
Subsystem
node:vm
What steps will reproduce the bug?
Needs
--experimental-vm-modules
flag
import { SourceTextModule } from 'node:vm'
async function linker() {
const fakeMod = new SourceTextModule('console.log("Hello, world!")')
await fakeMod.link(() => {})
await fakeMod.evaluate()
return fakeMod
}
const code = 'import("")'
const modA = new SourceTextModule(code, {
importModuleDynamically: linker,
})
const modB = new SourceTextModule(code, {
importModuleDynamically: linker,
cachedData: modA.createCachedData(),
})
await modA.link(linker)
await modA.evaluate() // logs "Hello, world!"
await modB.link(linker)
await modB.evaluate() // TypeError: Invalid host defined options
How often does it reproduce? Is there a required condition?
100% of the time when passing cachedData
What is the expected behavior?
Dynamic imports works as expected.
What do you see instead?
vm:module(0):1
import("")
^
TypeError: Invalid host defined options
at vm:module(0):1:1
at SourceTextModule.evaluate (node:internal/vm/module:226:23)
at file:///home/chooks/code/play/test.js:24:12
Additional information
- Works when
cachedData
is not passed. - Works when using static imports.
- Breaks even if returned the same reference to
fakeMod
.