Skip to content

feat: enable ESM worker chunk loading for Node.js targets #19640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

3ru
Copy link
Contributor

@3ru 3ru commented Jun 29, 2025

What kind of change does this PR introduce?

adds basic ESM worker support for Node.js targets.

What this PR enables:

  • Workers can be loaded as ES modules in Node.js using new Worker(url, { type: "module" })
  • workerChunkLoading: "import" configuration works when output.chunkFormat is "module"
  • Static ES module imports (import ... from ...) work inside workers

Current limitations:

  • Dynamic imports (await import()) inside workers do not yet split into separate chunks
  • All worker dependencies are bundled into a single worker file

Rel: #17121

Did you add tests for your changes?

Yes, added:

  • Unit test in test/Defaults.unittest.js to verify correct defaults generation
  • Integration test in test/configCases/worker/node-worker-esm/ to verify runtime behavior

npx jest test/Defaults.unittest.js -t "target node with ESM output" --updateSnapshot

Does this PR introduce a breaking change?

This change affects configurations that explicitly use ESM output (experiments.outputModule: true) with Node.js targets.

Copy link

codspeed-hq bot commented Jun 29, 2025

CodSpeed Performance Report

Merging #19640 will degrade performances by 94.1%

Comparing 3ru:feat/node-esm-worker-chunk-loading (e4f1117) with main (5bcd259)

Summary

⚡ 3 improvements
❌ 2 regressions
✅ 128 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
benchmark "devtool-eval", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 42.3 ms 11.4 ms ×3.7
benchmark "devtool-source-map", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 10.4 ms 43.2 ms -75.97%
benchmark "lodash", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 34.7 ms 10.5 ms ×3.3
benchmark "many-modules-esm", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 47.5 ms 9.8 ms ×4.8
benchmark "three-long", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 13.2 ms 223.8 ms -94.1%

@3ru 3ru force-pushed the feat/node-esm-worker-chunk-loading branch from e02f9f7 to e4f1117 Compare June 29, 2025 05:22
@3ru
Copy link
Contributor Author

3ru commented Jun 29, 2025

Memo:
Dynamic chunk loading within workers (e.g., await import() inside workers) is not yet supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant