Skip to content

SOURCEMAP_BROKEN warning from vite:css-post in the SSR build when sourcemaps are enabled #23809

Closed

Description

@lucasvidela94

Versions

  • vite 8.3.4
  • rolldown 1.2.14
  • @cloudflare/vite-plugin 1.64.0
  • @tanstack/react-start 1.169.3
  • @tailwindcss/vite 4.x

What happens

vite build for an SSR/server environment with sourcemaps enabled prints:

[plugin vite:css-post] [SOURCEMAP_BROKEN] Sourcemap is likely to be incorrect: a plugin (vite:css-post) was used to transform files, but didn't generate a sourcemap for the transformation.

Cause I found

In packages/vite/src/node/plugins/css.ts, the vite:css-post transform for a server consumer returns a bare string:

if (this.environment.config.consumer === 'server') return modulesCode || 'export {}'

It returns no map, so Rolldown reports that the transform has no sourcemap. The CSS module is replaced by an empty module, so there is nothing to map, but the check cannot tell.

Evidence

  • With build.sourcemap: false the warning disappears.
  • It appears only in the server environment; the client build is clean.
  • It happens with a plain import appCss from './styles.css?url' in the root route.
  • The sourcemaps are enabled by @cloudflare/vite-plugin (upload_source_maps: true), so turning them off is not an option for Workers stack traces.

Expected

No warning when the transform deliberately replaces the module. For example, return { code, map: { mappings: '' } }, as compileCSS already does elsewhere in the same file.

Workaround

build.rolldownOptions.checks.sourcemapBroken: false hides the warning, but it also hides real sourcemap problems from other plugins.

Reproduction

I do not have a standalone minimal reproduction yet. It reproduces in a TanStack Start project using @cloudflare/vite-plugin with viteEnvironment: { name: 'ssr' } and @tailwindcss/vite. I can add one if needed.

Activity

  1. added theissue type on Oct 18, 2026
  2. github-actions commented on Oct 18, 2026

    @github-actions
    Contributor

    Hello @lucasvidela94. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs reproduction will be closed if they have no activity within 3 days.

  3. tkowalczyk commented on Oct 20, 2026

    @tkowalczyk

    I hit the same warning (vite 8.3.4, rolldown 1.2.14, TanStack Start 1.169.3 + @cloudflare/vite-plugin 1.64.0) and traced it to a different line than the one in the description. Here's a minimal reproduction with only Vite.

    Cause

    The line quoted above (css.ts L621, if (this.environment.config.consumer === 'server') return modulesCode || 'export {}') is inside if (config.command === 'serve'), so it doesn't run in vite build. The build path of that transform already returns map: { mappings: '' }.

    The warning comes from renderChunk in vite:css-post. That hook rewrites the ?url CSS placeholder in the chunk with MagicString, then decides whether to return a map from the plugin's captured config (css.ts L991 at v8.3.4, L994 on main):

    if (s) {
      if (config.build.sourcemap) {
        return { code: s.toString(), map: s.generateMap({ hires: 'boundary' }) }
      } else {
        return { code: s.toString() }
      }
    }

    With builder.sharedPlugins or builder.sharedConfigBuild, the plugin is created once from the top-level config. An environment that enables sourcemaps only for itself therefore gets { code } with no map, and Rolldown reports SOURCEMAP_BROKEN. TanStack Start sets builder.sharedPlugins: true, and @cloudflare/vite-plugin turns sourcemaps on for the Worker environment only (upload_source_maps). That's why this combination hits it.

    Reproduction (Vite only)

    style.css is any CSS, and index.html loads an empty main.js.

    // vite.config.js
    export default {
      builder: { sharedPlugins: true },
      environments: {
        ssr: {
          build: {
            outDir: 'dist/server',
            sourcemap: true,
            rollupOptions: { input: 'server.js' },
          },
        },
      },
    }
    // server.js
    import cssUrl from './style.css?url'
    export default () => cssUrl

    vite build --app:

    builder top-level build.sourcemap SOURCEMAP_BROKEN
    {} unset no
    { sharedPlugins: true } unset yes
    { sharedConfigBuild: true } unset yes
    { sharedPlugins: true } true, with environments.client.build.sourcemap: false no

    The last row changes only the value that check reads. The server map is still emitted (server.mjs.map), and the warning is gone.

    Suggested fix

    -              if (config.build.sourcemap) {
    +              if (this.environment.config.build.sourcemap) {

    The same hook already reads this.environment.config.build.cssCodeSplit (L899). I haven't built Vite with this patch; the last row above is what isolates the check.

    Narrower workaround

    checks.sourcemapBroken: false hides every plugin's broken map. Filtering only this one keeps the rest:

    build: {
      rolldownOptions: {
        onLog(level, log, handler) {
          if (log.code === 'SOURCEMAP_BROKEN' && log.plugin === 'vite:css-post') return
          handler(level, log)
        },
      },
    },
  4. added
    p3-minor-bug
    feat: sourcemap
    and removed on Oct 21, 2026
  5. locked and limited conversation to collaborators on Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: sourcemapp3-minor-bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions