Skip to content

fix(babel): run parallel workers as ES modules - #176

Merged
sapphi-red merged 2 commits into
rolldown:mainfrom
NullVoxPopuli-ai-agent:nvp/babel-esm-workers
Nov 27, 2026
Merged

sapphi-red merged 2 commits into
rolldown:mainfrom
NullVoxPopuli-ai-agent:nvp/babel-esm-workers

Conversation

@NullVoxPopuli-ai-agent

Copy link
Copy Markdown
Contributor

With parallel, the workers now run as ES modules (artichokie type: 'module'). Babel plugins then see the same globals in a worker as on the main thread.

Before this, artichokie started each worker with new Worker(code, { eval: true }). In such a worker, require, module, __dirname and __filename are globals, and ES modules loaded in the worker can see them. On the main thread they are undefined. So some plugins gave other output with parallel:

Details: #139 (comment)

The new test runs a fixture plugin in a worker that writes typeof of the four globals into the output, and expects all four to be undefined. It fails without the change. I also built the package and ran the same fixture through dist/index.mjs, where the worker imports dist/transform.mjs from the data: URL module. It gave the same result.

🤖 Generated with Claude Code

artichokie runs worker code with `eval: true` by default, so `require`,
`module`, `__dirname` and `__filename` are globals in the worker.
Babel plugins that check for them gave different output with `parallel`
than on the main thread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@NullVoxPopuli NullVoxPopuli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy how small this turned out!

@sapphi-red sapphi-red left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sapphi-red sapphi-red changed the title fix(babel): run parallel workers as ES modules fix(babel): run parallel workers as ES modules Nov 27, 2026
@sapphi-red sapphi-red changed the title fix(babel): run parallel workers as ES modules fix(babel): run parallel workers as ES modules Nov 27, 2026
@sapphi-red
sapphi-red merged commit 725040d into rolldown:main Nov 27, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants