Skip to content

Using MessageChannel pulls in undici inappropriately #57581

Open
@webstrand

Description

@webstrand

Version

v22.13.1

Platform

Linux localhost 6.13.1-1-default #1 SMP PREEMPT_DYNAMIC Mon Feb  3 05:33:25 UTC 2025 (1918d13) x86_64 x86_64 x86_64 GNU/Linux

Subsystem

worker_threads

What steps will reproduce the bug?

Run this command:

node --jitless -e 'const { port1, port2 } = new MessageChannel(); port1.addEventListener("message", () => {});  port2.postMessage(null);'

or run this script with --jitless

const { port1, port2 } = new MessageChannel();
port1.addEventListener("message", () => {});
port2.postMessage(null);

How often does it reproduce? Is there a required condition?

Every time

What is the expected behavior? Why is that the expected behavior?

No exception should be thrown, undici should not be loaded when fetch is not needed.

What do you see instead?

> node --jitless -e 'const { port1, port2 } = new MessageChannel(); port1.addEventListener("message", () => {});  port2.postMessage(null);'
Warning: disabling flag --expose_wasm due to conflicting flags
node:internal/deps/undici/undici:5827
        mod = await WebAssembly.compile(llhttpWasmData || require_llhttp_wasm());
        ^

ReferenceError: WebAssembly is not defined
    at lazyllhttp (node:internal/deps/undici/undici:5827:9)
    at lib/dispatcher/client-h1.js (node:internal/deps/undici/undici:5873:25)
    at __require (node:internal/deps/undici/undici:6:50)
    at lib/dispatcher/client.js (node:internal/deps/undici/undici:7607:21)
    at __require (node:internal/deps/undici/undici:6:50)
    at lib/dispatcher/pool.js (node:internal/deps/undici/undici:8068:18)
    at __require (node:internal/deps/undici/undici:6:50)
    at lib/dispatcher/agent.js (node:internal/deps/undici/undici:8151:16)
    at __require (node:internal/deps/undici/undici:6:50)
    at lib/global.js (node:internal/deps/undici/undici:8251:17)

Node.js v22.13.1

Additional information

I believe this is due to constructing the MessageEvent, which appears to come from undici:

fastCreateMessageEvent ??= require('internal/deps/undici/undici').createFastMessageEvent;

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.

    Type

    No type

    Projects

    Status

    Awaiting Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions