{"record":{"id":"960ab232c7dd3c97","repo":"remotion-dev/remotion","slug":"parsemediaonserverworker-is-not-available-in-cjs-m","errorCode":null,"errorMessage":"parseMediaOnServerWorker is not available in CJS mode. Load this function using ESM to use it.","messagePattern":"parseMediaOnServerWorker 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/server-worker.ts","lineNumber":6,"sourceCode":"import type {ParseMediaOnWorker} from './options';\n\nexport type {ParseMediaOnWorker, ParseMediaOnWorkerOptions} from './options';\n\nexport const parseMediaOnServerWorker: ParseMediaOnWorker = () => {\n\tthrow new Error(\n\t\t'parseMediaOnServerWorker is not available in CJS mode. Load this function using ESM to use it.',\n\t);\n};\n","sourceCodeStart":1,"sourceCodeEnd":10,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/server-worker.ts#L1-L10","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (CJS)\nconst { parseMediaOnServerWorker } = require('@remotion/media-parser/server-worker');\n\n// after (ESM)\nimport { parseMediaOnServerWorker } from '@remotion/media-parser/server-worker';","handlingStrategy":"fallback","validationCode":"// Detect CJS resolution at runtime\nconst isCjs = typeof require === 'function' && typeof module !== 'undefined' && module.exports;\nif (isCjs) throw new Error('Load @remotion/media-parser/server-worker via ESM');","typeGuard":"const supportsEsm = () => typeof import.meta !== 'undefined' && 'url' in import.meta;","tryCatchPattern":"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; }","preventionTips":["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."],"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"}