Skip to content

fix(bundle): Deno.bundle work in Worker - #31316

Merged
nathanwhit merged 1 commit into
denoland:mainfrom
kuboon:fix/bundle-in-worker
Nov 18, 2025
Merged

nathanwhit merged 1 commit into
denoland:mainfrom
kuboon:fix/bundle-in-worker

Conversation

@kuboon

@kuboon kuboon commented Nov 17, 2025 •

Copy link
Copy Markdown
Contributor

Currently, Deno.bundle throws exception in a Worker.

error: Uncaught (in worker "") (in promise) Error: default BundleProvider does not do anything

This PR passes the clone of BundleProvider to workers.


minimum reproduction:

#! /usr/bin/env -S deno run --allow-read=. --unstable-bundle

if (typeof WorkerGlobalScope === "undefined") {
  const worker = new Worker(import.meta.url, { type: "module" });
  worker.onmessage = () => Deno.exit();
} else {
  await Deno.bundle({
    entrypoints: [import.meta.url],
    write: false
  });
  postMessage("done");
}

Copilot AI review requested due to automatic review settings November 17, 2025 01:03
@CLAassistant

CLAassistant commented Nov 17, 2025 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI 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.

Pull Request Overview

This PR fixes a bug where Deno.bundle would throw an exception when called from within a Worker context. The fix involves passing the bundle provider to workers so they can perform bundling operations.

Key Changes

  • Added bundle_provider field to WebWorkerServiceOptions to enable bundle functionality in workers
  • Modified worker initialization to pass the cloned bundle provider from the main worker factory
  • Added comprehensive test coverage for bundling within a worker context

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
runtime/web_worker.rs Added bundle_provider field to WebWorkerServiceOptions struct and passed it to the bundle runtime initialization
cli/lib/worker.rs Populated the bundle_provider field when creating web worker services from the shared state
tests/specs/bundle/worker/test.jsonc Added test configuration for bundling in worker context
tests/specs/bundle/worker/main.ts Test entry point that creates a worker for bundle testing
tests/specs/bundle/worker/worker.ts Worker implementation that performs bundling and verifies the result
tests/specs/bundle/worker/main.ts.out Expected test output showing successful bundling in worker

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kuboon
kuboon force-pushed the fix/bundle-in-worker branch from 83cfe38 to fb87326 Compare November 17, 2025 09:32
@kuboon
kuboon force-pushed the fix/bundle-in-worker branch from fb87326 to 797c284 Compare November 17, 2025 09:45

@nathanwhit nathanwhit 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, thanks for the PR!

@nathanwhit
nathanwhit merged commit e935523 into denoland:main Nov 18, 2025
@kuboon
kuboon deleted the fix/bundle-in-worker branch November 18, 2025 12:44
bartlomieju pushed a commit that referenced this pull request Jan 22, 2026
Currently, `Deno.bundle` throws exception in a `Worker`.

```
error: Uncaught (in worker "") (in promise) Error: default BundleProvider does not do anything
```

This PR passes the clone of BundleProvider to workers.

---
minimum reproduction:
```ts
#! /usr/bin/env -S deno run --allow-read=. --unstable-bundle

if (typeof WorkerGlobalScope === "undefined") {
  const worker = new Worker(import.meta.url, { type: "module" });
  worker.onmessage = () => Deno.exit();
} else {
  await Deno.bundle({
    entrypoints: [import.meta.url],
    write: false
  });
  postMessage("done");
}
```
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.

4 participants