Skip to content

worker: strip types in Web Worker module entries - #66085

Open
osztenkurden wants to merge 3 commits into
nodejs:mainfrom
osztenkurden:fix/webworker-typescript-entry
Open

osztenkurden wants to merge 3 commits into
nodejs:mainfrom
osztenkurden:fix/webworker-typescript-entry

Conversation

@osztenkurden

Copy link
Copy Markdown

The experimental Web Worker module entries don't perform TypeScript stripping: type annotations in the entry file cause a SyntaxError, even though a JavaScript-compatible entry importing files with TypeScript annotations succeeds.

The proposed solution is to strip types from file-backed .ts, .mts, and .cts module-worker entries before evaluation, preserving existing fetching and worker-type semantics.

Strip TypeScript from file-backed module worker entries before
evaluating the fetched source.

Add regression coverage and document the supported entry types.

Assisted-by: Codex
Signed-off-by: Hubert Walczak <hubertwalczak8@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/typescript

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Sep 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.30%. Comparing base (fa95cd5) to head (acbfc92).
⚠️ Report is 118 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66085      +/-   ##
==========================================
+ Coverage   90.27%   90.30%   +0.03%     
==========================================
  Files         789      789              
  Lines      271623   272896    +1273     
  Branches    51847    52119     +272     
==========================================
+ Hits       245196   246432    +1236     
- Misses      16910    16914       +4     
- Partials     9517     9550      +33     
Files with missing lines Coverage Δ
lib/internal/webworker.js 93.22% <100.00%> (+0.12%) ⬆️

... and 119 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Pass the decoded path to stripTypeScriptModuleTypes() so it does the
node_modules check, instead of repeating it in webworker.js.

Shorten the note in globals.md and drop the typescript.md paragraph.
Remove test cases that repeat what other cases already cover.

Signed-off-by: Hubert Walczak <hubertwalczak8@gmail.com>
@osztenkurden
osztenkurden force-pushed the fix/webworker-typescript-entry branch from 60307c1 to 29c8d52 Compare September 23, 2026 08:25
@osztenkurden

Copy link
Copy Markdown
Author

@avivkeller would you mind taking a quick look? 🙏 Currently running TypeScript entry WebWorker fails, and that adds a bit of boilerplate

@avivkeller avivkeller 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.

LGTM, and thanks for the ping! just note it's differing from the HTML Spec (which is fine, but @nodejs/web-standards should take a look)

Comment thread doc/api/globals.md Outdated
Comment thread lib/internal/webworker.js Outdated
@avivkeller avivkeller added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Sep 23, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 23, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@KhafraDev

Copy link
Copy Markdown
Member

Why would web workers strip types?

Comment thread lib/internal/webworker.js
Comment thread doc/api/globals.md Outdated

@jasnell jasnell 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.

Generally LGTM but I think we should probably handle it as independently experimental in case we need to tweak it separately from graduating the main web worker implementation.

Lazy load the type stripping helper with getLazy(), and list type
stripping under the differences from the HTML Standard.

Signed-off-by: Hubert Walczak <hubertwalczak8@gmail.com>
@osztenkurden

Copy link
Copy Markdown
Author

@KhafraDev my reasoning was that if the type stripping was actually already working in worker_threads and in modules that Web Worker imports, then making entry point with types work seemed like a good idea and putting everything in line.

@KhafraDev

Copy link
Copy Markdown
Member

I'm fine with it landing.

@mcollina mcollina 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.

lgtm

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

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants