Skip to content

πŸŽ₯ Make videos programmatically with React

add comment note

Igor Samokhovets2c2ac38153d1
diff --git a/packages/studio/bundle.ts b/packages/studio/bundle.ts
index c6eeac3b11..9f786e1d0b 100644
--- a/packages/studio/bundle.ts
+++ b/packages/studio/bundle.ts
@@ -56,9 +56,18 @@ await buildPackage({
// Mirror the ESM worker asset next to the CJS helper. Webpack/rspack resolves
// `new Worker(new URL('./audio-waveform-worker.mjs', import.meta.url))` from
// the helper's location, so consumers loading `@remotion/studio` via CJS need
-// the worker to exist as a sibling at `dist/`. The cleaner alternative
-// (aliasing `@remotion/studio` to ESM) breaks visual controls because the
-// bundled ESM entries duplicate the visual-control singleton.
+// the worker to exist as a sibling at `dist/`.
+//
+// We tried two cleaner alternatives, both of which failed:
+// 1. Aliasing `@remotion/studio` to its ESM build in shared-bundler-config:
+// causes a dual-package hazard with the visualControlStore singleton
+// (user code and previewEntry get separate copies, breaking the
+// Controls panel β€” caught by visual-controls.test.mts).
+// 2. Using a bare specifier `@remotion/studio/audio-waveform-worker` with
+// a `./audio-waveform-worker` exports entry: webpack/rspack does not
+// resolve bare specifiers via package `exports` inside
+// `new URL(..., import.meta.url)` for workers; only relative paths
+// are statically analysed.
const esmWorker = 'dist/esm/audio-waveform-worker.mjs';
if (existsSync(esmWorker)) {
copyFileSync(esmWorker, 'dist/audio-waveform-worker.mjs');