vitejs/vite · error · Error

Unsupported output format ${outputOptions.format}

Error message

Unsupported output format ${outputOptions.format}

What it means

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.

Source

Thrown at packages/vite/rolldown.config.ts:376

          )
          if (!originalFile) {
            throw new Error(
              `Could not find original file for ${prefix}${index} in ${chunk.fileName}`,
            )
          }
          const outputFile = path.resolve(outputOptions.dir!, chunk.fileName)
          const relativePath = path
            .relative(path.dirname(outputFile), originalFile)
            .replaceAll('\\', '/')

          if (outputOptions.format === 'es') {
            return `new URL(${JSON.stringify(relativePath)}, import.meta.url)`
          } else if (outputOptions.format === 'cjs') {
            return `new URL(${JSON.stringify(
              relativePath,
            )}, require('node:url').pathToFileURL(__filename))`
          } else {
            throw new Error(`Unsupported output format ${outputOptions.format}`)
          }
        },
      )
    },
  }
}

/**
 * Guard the bundle size
 *
 * @param limit size in kB
 */
function bundleSizeLimit(limit: number): Plugin {
  let size = 0

  return {
    name: 'bundle-limit',
    generateBundle(_, bundle) {

View on GitHub (pinned to 89620f09af)

Solutions

  1. Keep the output format as 'es' or 'cjs' for configs that include src/ files with import.meta.url.
  2. If a different format is needed, exclude buildTimeImportMetaUrlPlugin from that config or extend it to handle the new format.
  3. Add a format-specific branch to the renderChunk replacement logic if the format genuinely needs support.

Example fix

// before — unsupported format for import.meta.url replacement
output: { format: 'umd', name: 'Vite' }
// after — use esm which supports import.meta.url natively
output: { format: 'esm' }
Defensive patterns

Strategy: validation

Validate before calling

// For Vite contributors: validate output format supports import.meta.url
const SUPPORTED_FORMATS = new Set(['es', 'cjs', 'esm'])
function validateFormatForImportMetaUrl(format) {
  if (!SUPPORTED_FORMATS.has(format)) {
    throw new Error(`Output format ${format} not supported by buildTimeImportMetaUrlPlugin`)
  }
}

Type guard

function supportsImportMetaUrl(format: string): boolean {
  return format === 'es' || format === 'cjs' || format === 'esm'
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of vitejs/vite@89620f09af (2026-08-03). Data as JSON: /data/errors/27d2339b88de24bd.json. Report an issue: GitHub.