vitejs/vite · error · Error

css content for ${JSON.stringify(id)} was not found

Error message

css content for ${JSON.stringify(id)} was not found

What it means

Thrown during build (`renderChunk`) when a generated chunk contains a `__VITE_CSS_URL__` placeholder referencing a CSS id that is not present in the in-memory `styles` map. Vite builds that placeholder earlier (in the `load` hook for `?url` CSS) and resolves it here; a missing entry means the CSS module was never compiled or was evicted before its URL asset could be emitted.

Source

Thrown at packages/vite/src/node/plugins/css.ts:814

              originalFileName: string
              content: string
              start: number
              end: number
            }> = []

            if (code.includes('__VITE_CSS_URL__')) {
              let match: RegExpExecArray | null
              cssUrlAssetRE.lastIndex = 0
              while ((match = cssUrlAssetRE.exec(code))) {
                const [full, idHex] = match
                const id = Buffer.from(idHex, 'hex').toString()
                const originalFileName = cleanUrl(id)
                const cssAssetName = ensureFileExt(
                  path.basename(originalFileName),
                  '.css',
                )
                if (!styles.has(id)) {
                  throw new Error(
                    `css content for ${JSON.stringify(id)} was not found`,
                  )
                }

                let cssContent = styles.get(id)!

                cssContent = resolveAssetUrlsInCss(
                  cssContent,
                  cssAssetName,
                  originalFileName,
                )

                urlEmitTasks.push({
                  cssAssetName,
                  originalFileName,
                  content: cssContent,
                  start: match.index,
                  end: match.index + full.length,

View on GitHub (pinned to 89620f09af)

Solutions

  1. Ensure every `*.css?url` imported file is actually processed by Vite's CSS plugin (don't intercept `*.css` in a custom plugin).
  2. Remove any `?url` CSS imports for files that are dynamically excluded from the build.
  3. Clear build cache and `node_modules/.vite`, then rebuild.
  4. Upgrade Vite — placeholder/`styles` map consistency bugs are fixed in patch releases.

Example fix

// before — custom plugin skips css load
{ name: 'x', load(id) { if (id.endsWith('.css')) return '' } }
// after — let vite handle css
{ name: 'x', load(id) { if (id.endsWith('.txt')) return '' } }
Defensive patterns

Strategy: validation

Try / catch

try {
  await build();
} catch (e) {
  if (/css content .* was not found/.test(e.message)) {
    console.error('A ?url CSS file was not compiled — check custom CSS plugins');
  }
  throw e;
}

Prevention

When it happens

Trigger: In `renderChunk`, for each `cssUrlAssetRE` match, the hex-decoded id must exist in `styles`. If `styles.has(id)` is false, the error fires.

Common situations: Build with `?url` CSS imports combined with custom plugins that skip/short-circuit CSS compilation, CSS emitted conditionally via multiple environments, or version mismatches after upgrading Vite where the placeholder format changed.

Related errors


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