{"record":{"id":"7eaf678fdf35d7ea","repo":"remotion-dev/remotion","slug":"parsemediaonwebworker-is-not-available-in-cjs-mode","errorCode":null,"errorMessage":"parseMediaOnWebWorker is not available in CJS mode. Load this function using ESM to use it.","messagePattern":"parseMediaOnWebWorker is not available in CJS mode\\. Load this function using ESM to use it\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/worker.ts","lineNumber":14,"sourceCode":"export {\n\thasBeenAborted,\n\tImageType,\n\tIsAnImageError,\n\tIsAnUnsupportedFileTypeError,\n\tIsAPdfError,\n\tMediaParserAbortError,\n} from './errors';\nimport type {ParseMediaOnWorker} from './options';\n\nexport type {ParseMediaOnWorker, ParseMediaOnWorkerOptions} from './options';\n\nexport const parseMediaOnWebWorker: ParseMediaOnWorker = () => {\n\tthrow new Error(\n\t\t'parseMediaOnWebWorker is not available in CJS mode. Load this function using ESM to use it.',\n\t);\n};\n","sourceCodeStart":1,"sourceCodeEnd":18,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/worker.ts#L1-L18","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (CJS)\nconst { parseMediaOnWebWorker } = require('@remotion/media-parser/worker');\n\n// after (ESM)\nimport { parseMediaOnWebWorker } from '@remotion/media-parser/worker';","handlingStrategy":"fallback","validationCode":"// Detect CJS context\nconst isCjs = typeof require === 'function';\nif (isCjs) console.warn('Load @remotion/media-parser/worker via ESM');","typeGuard":"const supportsEsm = () => typeof import.meta !== 'undefined' && 'url' in import.meta;","tryCatchPattern":"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; }","preventionTips":["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."],"tags":["media-parser","worker","cjs","esm","module-system"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}