{"id":"27d2339b88de24bd","repo":"vitejs/vite","slug":"unsupported-output-format-outputoptions-format","errorCode":null,"errorMessage":"Unsupported output format ${outputOptions.format}","messagePattern":"Unsupported output format (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/rolldown.config.ts","lineNumber":376,"sourceCode":"          )\n          if (!originalFile) {\n            throw new Error(\n              `Could not find original file for ${prefix}${index} in ${chunk.fileName}`,\n            )\n          }\n          const outputFile = path.resolve(outputOptions.dir!, chunk.fileName)\n          const relativePath = path\n            .relative(path.dirname(outputFile), originalFile)\n            .replaceAll('\\\\', '/')\n\n          if (outputOptions.format === 'es') {\n            return `new URL(${JSON.stringify(relativePath)}, import.meta.url)`\n          } else if (outputOptions.format === 'cjs') {\n            return `new URL(${JSON.stringify(\n              relativePath,\n            )}, require('node:url').pathToFileURL(__filename))`\n          } else {\n            throw new Error(`Unsupported output format ${outputOptions.format}`)\n          }\n        },\n      )\n    },\n  }\n}\n\n/**\n * Guard the bundle size\n *\n * @param limit size in kB\n */\nfunction bundleSizeLimit(limit: number): Plugin {\n  let size = 0\n\n  return {\n    name: 'bundle-limit',\n    generateBundle(_, bundle) {","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/rolldown.config.ts#L358-L394","documentation":"Thrown by buildTimeImportMetaUrlPlugin's renderChunk when the output format is neither 'es' (ESM) nor 'cjs' (CommonJS). The plugin generates format-specific code to reconstruct import.meta.url at runtime — new URL(..., import.meta.url) for ES, and new URL(..., require('node:url').pathToFileURL(__filename)) for CJS. Other formats (umd, iife, amd, system) are unsupported because they don't provide a reliable mechanism to derive the module URL.","triggerScenarios":"Changing Vite's build output format in rolldown.config.ts to 'umd', 'iife', 'amd', or 'system' while the buildTimeImportMetaUrlPlugin is active and the source code contains import.meta.url references in src/ files.","commonSituations":"A Vite contributor experiments with alternative output formats for the Vite node bundle. Since Vite's own build uses esm format for node and browser configs, this only triggers when someone explicitly changes the format option. Not an end-user error.","solutions":["Keep the output format as 'es' or 'cjs' for configs that include src/ files with import.meta.url.","If a different format is needed, exclude buildTimeImportMetaUrlPlugin from that config or extend it to handle the new format.","Add a format-specific branch to the renderChunk replacement logic if the format genuinely needs support."],"exampleFix":"// before — unsupported format for import.meta.url replacement\noutput: { format: 'umd', name: 'Vite' }\n// after — use esm which supports import.meta.url natively\noutput: { format: 'esm' }","handlingStrategy":"validation","validationCode":"// For Vite contributors: validate output format supports import.meta.url\nconst SUPPORTED_FORMATS = new Set(['es', 'cjs', 'esm'])\nfunction validateFormatForImportMetaUrl(format) {\n  if (!SUPPORTED_FORMATS.has(format)) {\n    throw new Error(`Output format ${format} not supported by buildTimeImportMetaUrlPlugin`)\n  }\n}","typeGuard":"function supportsImportMetaUrl(format: string): boolean {\n  return format === 'es' || format === 'cjs' || format === 'esm'\n}","tryCatchPattern":null,"preventionTips":["Use 'es' or 'esm' format for configs that process src/ files with import.meta.url.","If you need 'umd'/'iife', exclude or extend buildTimeImportMetaUrlPlugin.","Document format constraints in the config file comments."],"tags":["rolldown-config","output-format","import-meta-url","internal-vite-build"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}