remotion-dev/remotion · error · Error
parseMediaOnWebWorker is not available in CJS mode. Load thi
Error message
parseMediaOnWebWorker is not available in CJS mode. Load this function using ESM to use it.
What it means
Thrown by the CommonJS stub of parseMediaOnWebWorker in worker.ts. The web worker entry depends on import.meta.url and new Worker, both ESM-only constructs; when the package is loaded as CJS this stub is selected and always throws to tell the caller to load the ESM build.
Source
Thrown at packages/media-parser/src/worker.ts:14
export {
hasBeenAborted,
ImageType,
IsAnImageError,
IsAnUnsupportedFileTypeError,
IsAPdfError,
MediaParserAbortError,
} from './errors';
import type {ParseMediaOnWorker} from './options';
export type {ParseMediaOnWorker, ParseMediaOnWorkerOptions} from './options';
export const parseMediaOnWebWorker: ParseMediaOnWorker = () => {
throw new Error(
'parseMediaOnWebWorker is not available in CJS mode. Load this function using ESM to use it.',
);
};
View on GitHub (pinned to 78fe4bb3fd)
Solutions
- Import the web worker via ESM: use import or dynamic import() so the .module entry resolves.
- Configure the bundler/tsconfig to ESM (module:'esnext', moduleResolution:'bundler').
- If ESM is impossible, use the in-process parseMedia which works under CJS.
Example fix
// before (CJS)
const { parseMediaOnWebWorker } = require('@remotion/media-parser/worker');
// after (ESM)
import { parseMediaOnWebWorker } from '@remotion/media-parser/worker'; Defensive patterns
Strategy: fallback
Validate before calling
// Detect CJS context
const isCjs = typeof require === 'function';
if (isCjs) console.warn('Load @remotion/media-parser/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/worker'); return await m.parseMediaOnWebWorker(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
- Configure bundler/tsconfig to ESM when using the web worker entry.
- Use dynamic import() from CJS contexts.
- Fall back to in-process parseMedia when ESM is unavailable.
When it happens
Trigger: Requiring @remotion/media-parser/worker via require() (CJS) instead of importing it as ESM. Common in older Node configs, CJS-only bundler outputs, or frameworks that force CJS resolution for subpaths.
Common situations: A CJS Next.js pages router or Express handler that resolves the worker subpath to the CJS build. tsconfig with module:'commonjs'. Migrating ESM Remotion code into a legacy CJS pipeline.
Related errors
- parseMediaOnServerWorker is not available in CJS mode. Load
- "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/7eaf678fdf35d7ea.
Report an issue: GitHub.