Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Restore CJS worker mirror to fix visual controls

Igor Samokhovets8201ab192bbc
diff --git a/packages/bundler/src/shared-bundler-config.ts b/packages/bundler/src/shared-bundler-config.ts
index c20a7cde17..cb69b0a07e 100644
--- a/packages/bundler/src/shared-bundler-config.ts
+++ b/packages/bundler/src/shared-bundler-config.ts
@@ -57,15 +57,8 @@ export const getResolveConfig = () => ({
'esm',
'worker.mjs',
),
- // Resolve to the ESM build so `new Worker(new URL(..., import.meta.url))`
- // patterns inside Studio are recognised by rspack/webpack.
// test visual controls before removing this
- '@remotion/studio': path.resolve(
- require.resolve('@remotion/studio'),
- '..',
- 'esm',
- 'index.mjs',
- ),
+ '@remotion/studio': require.resolve('@remotion/studio'),
'react-dom/client': shouldUseReactDomClient
? require.resolve('react-dom/client')
: require.resolve('react-dom'),
diff --git a/packages/cli/src/studio.ts b/packages/cli/src/studio.ts
index 2d8547e368..c883198838 100644
--- a/packages/cli/src/studio.ts
+++ b/packages/cli/src/studio.ts
@@ -1,4 +1,3 @@
-import path from 'node:path';
import type {LogLevel} from '@remotion/renderer';
import {BrowserSafeApis} from '@remotion/renderer/client';
import {StudioServerInternals} from '@remotion/studio-server';
@@ -161,12 +160,7 @@ export const studioCommand = async (
}
const result = await StudioServerInternals.startStudio({
- previewEntry: path.join(
- require.resolve('@remotion/studio/previewEntry'),
- '..',
- 'esm',
- 'previewEntry.mjs',
- ),
+ previewEntry: require.resolve('@remotion/studio/previewEntry'),
browserArgs: parsedCli['browser-args'],
browserFlag: browserOption.getValue({commandLine: parsedCli}).value ?? '',
logLevel,
diff --git a/packages/studio/bundle.ts b/packages/studio/bundle.ts
index c214bd70c1..c6eeac3b11 100644
--- a/packages/studio/bundle.ts
+++ b/packages/studio/bundle.ts
@@ -1,3 +1,4 @@
+import {copyFileSync, existsSync} from 'fs';
import {buildPackage} from '../.monorepo/builder';
const external = [
@@ -51,3 +52,14 @@ 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.
+const esmWorker = 'dist/esm/audio-waveform-worker.mjs';
+if (existsSync(esmWorker)) {
+ copyFileSync(esmWorker, 'dist/audio-waveform-worker.mjs');
+}