{"record":{"id":"473561528c2dff32","repo":"remotion-dev/remotion","slug":"detected-vite-pre-bundling-which-will-break-the-w","errorCode":null,"errorMessage":"Detected Vite pre-bundling, which will break the worker.\nPlease add the following to your vite.config.js:\n  optimizeDeps: {\n    exclude: [\"@remotion/media-parser/worker\"]\n  }","messagePattern":"Detected Vite pre-bundling, which will break the worker\\.\nPlease add the following to your vite\\.config\\.js:\n  optimizeDeps: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/worker.module.ts","lineNumber":34,"sourceCode":"\tF extends Options<ParseMediaFields>,\n>(\n\tparams: ParseMediaOnWorkerOptions<F>,\n) => {\n\tif (typeof Worker === 'undefined') {\n\t\tthrow new Error(\n\t\t\t'\"Worker\" is not available. Cannot call parseMediaOnWebWorker()',\n\t\t);\n\t}\n\n\tif (import.meta.url.includes('.vite/deps')) {\n\t\tconst err = [\n\t\t\t'Detected Vite pre-bundling, which will break the worker.',\n\t\t\t'Please add the following to your vite.config.js:',\n\t\t\t'  optimizeDeps: {',\n\t\t\t'    exclude: [\"@remotion/media-parser/worker\"]',\n\t\t\t'  }',\n\t\t].join('\\n');\n\t\tthrow new Error(err);\n\t}\n\n\tconst worker = new Worker(new URL('./worker-web-entry.mjs', import.meta.url));\n\n\treturn parseMediaOnWorkerImplementation(\n\t\tparams,\n\t\tworker,\n\t\t'parseMediaOnWebWorker',\n\t);\n};\n","sourceCodeStart":16,"sourceCodeEnd":45,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/worker.module.ts#L16-L45","documentation":"Thrown by parseMediaOnWebWorker when import.meta.url contains '.vite/deps', indicating Vite pre-bundled the worker entry. Vite's dependency pre-bundling breaks worker instantiation because it rewrites module URLs and the new URL('./worker-web-entry.mjs', import.meta.url) pattern no longer resolves to a servable worker script.","triggerScenarios":"Using parseMediaOnWebWorker inside a Vite-powered app (Vite dev server or build) without excluding @remotion/media-parser/worker from optimizeDeps. Vite pre-bundles the package, the worker URL is rewritten, and the guard trips to fail fast rather than producing a broken worker.","commonSituations":"New Vite project importing the media-parser web worker. Upgrading Vite and hitting stricter pre-bundling. Copying a snippet from a non-Vite project into a Vite app without adjusting the config.","solutions":["Add optimizeDeps.exclude: ['@remotion/media-parser/worker'] to vite.config as the error message instructs.","If the error persists, also exclude the package from build.rollupOptions or use the in-process parseMedia instead.","Restart the Vite dev server after editing vite.config so optimizeDeps cache is rebuilt."],"exampleFix":"// before - vite.config.js\nexport default { plugins: [react()] };\n\n// after\nexport default {\n  plugins: [react()],\n  optimizeDeps: { exclude: ['@remotion/media-parser/worker'] },\n};","handlingStrategy":"validation","validationCode":"// vite.config.js\nexport default {\n  optimizeDeps: { exclude: ['@remotion/media-parser/worker'] },\n};","typeGuard":null,"tryCatchPattern":"try { await parseMediaOnWebWorker(opts); } catch (e) { if (/Vite pre-bundling/.test(String((e as Error).message))) { console.error('Add optimizeDeps.exclude for @remotion/media-parser/worker, then restart Vite'); } throw e; }","preventionTips":["Add optimizeDeps.exclude for @remotion/media-parser/worker in every Vite project using it.","Restart the Vite dev server after editing optimizeDeps.","Keep a project template config snippet for this exclusion."],"tags":["media-parser","worker","vite","bundler","config"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}