Skip to content

Pass a literal worker type so Vite can bundle the ESM build - #124

Merged
Project516 merged 1 commit into
masterfrom
vite-worker-type
Oct 29, 2026
Merged

Project516 merged 1 commit into
masterfrom
vite-worker-type

Conversation

@Project516

Copy link
Copy Markdown
Owner

vite build fails on any app that imports @project516/ffmpeg-wasm 0.17.0:

[plugin vite:worker-import-meta-url] .../@project516/ffmpeg-wasm/dist/esm/classes.js
Error: Expected worker options type property to be a literal value.

Vite only bundles new Worker(new URL(...), { type }) when type is a literal. The ESM build has passed WORKER_TYPE, a variable, since #6. The bundled worker branch in classes.ts now passes type: "module".

The UMD build keeps its classic worker. Webpack's worker plugin replaces the type of a worker it bundles with undefined when the output is not ESM, so dist/umd/ffmpeg.js still has {type:void 0}, the same as before. The classWorkerURL branch still uses WORKER_TYPE, because neither bundler handles that call.

Testing

  • pnpm build and pnpm lint pass.
  • dist/esm/classes.js has type: "module", and dist/umd/ffmpeg.js has {type:void 0} for the bundled worker.
  • apps/sveltekit-app with Vite 8 fails vite build against the published 0.17.0 with the error above. With this one-line change applied to the installed classes.js, it builds and emits the worker chunk. On master the same app with Vite 6 fails the same way.
  • CI runs the browser tests on the ESM and UMD builds.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 42 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 6b2195e9-8cfb-4713-96aa-c57fdf34328f
Commits

Reviewing files that changed from the base of the PR and between b05c356 and b217cde.

Files selected for processing: 2
  • CHANGELOG.md
  • packages/ffmpeg/src/classes.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The PR fixes a Vite bundling failure by changing the worker type from a variable (WORKER_TYPE) to a literal string ("module") in the ESM build's bundled worker branch. Vite requires the type option to be a literal for static analysis. The UMD build is unaffected and continues to use the classic worker pattern. Testing confirms the fix works with Vite 6 and 8, and both pnpm build and pnpm lint pass.


review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict approve

@Project516
Project516 merged commit 4aa42e2 into master Oct 29, 2026
29 checks passed
@Project516
Project516 deleted the vite-worker-type branch October 29, 2026 14:41
@Project516 Project516 mentioned this pull request Oct 29, 2026
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