remotion-dev/remotion · error · Error
parseMediaOnServerWorker is not available in CJS mode. Load
Error message
parseMediaOnServerWorker is not available in CJS mode. Load this function using ESM to use it.
What it means
Thrown by the CommonJS stub of parseMediaOnServerWorker in server-worker.ts. The server worker entry relies on import.meta.url and new Worker, which require ESM; when the package is loaded as CJS this stub is resolved instead and always throws to signal that the caller must import the ESM build.
Source
Thrown at packages/media-parser/src/server-worker.ts:6
import type {ParseMediaOnWorker} from './options';
export type {ParseMediaOnWorker, ParseMediaOnWorkerOptions} from './options';
export const parseMediaOnServerWorker: ParseMediaOnWorker = () => {
throw new Error(
'parseMediaOnServerWorker is not available in CJS mode. Load this function using ESM to use it.',
);
};
View on GitHub (pinned to 78fe4bb3fd)
Solutions
- Import the server worker via ESM: use dynamic import() or set type:'module' / module:'esnext' so the .module entry is resolved.
- Target the ESM entry explicitly, e.g. import('@remotion/media-parser/server-worker').
- If ESM is impossible in that code path, use parseMedia (in-process) instead of the server-worker variant.
Example fix
// before (CJS)
const { parseMediaOnServerWorker } = require('@remotion/media-parser/server-worker');
// after (ESM)
import { parseMediaOnServerWorker } from '@remotion/media-parser/server-worker'; Defensive patterns
Strategy: fallback
Validate before calling
// Detect CJS resolution at runtime
const isCjs = typeof require === 'function' && typeof module !== 'undefined' && module.exports;
if (isCjs) throw new Error('Load @remotion/media-parser/server-worker via ESM'); Type guard
const supportsEsm = () => typeof import.meta !== 'undefined' && 'url' in import.meta;
Try / catch
try { const m = await import('@remotion/media-parser/server-worker'); return await m.parseMediaOnServerWorker(opts); } catch (e) { if (/not available in CJS mode/.test(String((e as Error).message))) { const { parseMedia } = await import('@remotion/media-parser'); return parseMedia(opts); } else throw e; } Prevention
- Set type:module / module:esnext to load ESM.
- Use dynamic import() for the worker entry from CJS contexts.
- Fall back to in-process parseMedia when ESM is impossible.
When it happens
Trigger: Requiring @remotion/media-parser/server-worker via require() (CJS) instead of importing it as ESM. Happens in older Node configs, CommonJS-only bundler outputs, or when tsconfig/module resolution forces CJS.
Common situations: A Next.js pages router or other CJS context that resolves the CJS build. Bundler configs with module:'commonjs'. Migrating an ESM Remotion project into a legacy CJS toolchain.
Related errors
- parseMediaOnWebWorker is not available in CJS mode. Load thi
- "Worker" is not available. Cannot call parseMediaOnServerWor
- "Worker" is not available. Cannot call parseMediaOnWebWorker
- `reader` should not be provided to `${apiName}`. If you want
- Detected Vite pre-bundling, which will break the worker. Ple
AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12).
Data as JSON: /api/errors/960ab232c7dd3c97.
Report an issue: GitHub.