Skip to content

SourceTextModule: Using dynamic imports while passing cachedData throws TypeError: Invalid host defined options #43663

Description

@Chooks22

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.v8 engineIssues and PRs related to the V8 dependency.vmIssues and PRs related to the vm subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions