From 73983e1cf5bc0ae721f4568cc24a5b5067b6b90b Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 22 May 2026 17:57:25 +0200 Subject: [PATCH] Fix 'Sourcemap is likely to be incorrect' warnings when using `@tailwindcss/vite` (#20103) This PR fixes an issue where a bunch of warnings would be shown related to sourcemaps. This happens when we are dealing with CSS files that are _not_ Tailwind CSS roots. In that case, in the `transform` step, we return the `src` of that module as-is because we didn't modify anything. However, when nothing changed, you have to return a `NullValue` such as `undefined`. So this is a stupid little fix, but it should get rid of a bunch of annoying warnings. Fixes: #19930 ## Test plan - Added an integration test to mimic the problem - Other tests still pass - Tested it against the reproduction provided in #19930 Before: 8oQNG5Lqr2B After: 8oQND5kWSb4 --- CHANGELOG.md | 1 + integrations/vite/source-maps.test.ts | 64 +++++++++++++++++++++++++ packages/@tailwindcss-vite/src/index.ts | 4 +- 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 366e11780..f3fb21590 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Allow `@apply` to be used with CSS mixins ([#19427](https://github.com/tailwindlabs/tailwindcss/pull/19427)) - Ensure `not-*` correctly negates `@container` queries, including `style(…)` queries ([#20059](https://github.com/tailwindlabs/tailwindcss/pull/20059)) - Ensure `drop-shadow-*` color utilities work with custom shadow values containing `calc(…)` ([#20080](https://github.com/tailwindlabs/tailwindcss/pull/20080)) +- Fix 'Sourcemap is likely to be incorrect' warnings when using `@tailwindcss/vite` ([#20103](https://github.com/tailwindlabs/tailwindcss/pull/20103)) ## [4.3.0] - 2026-05-08 diff --git a/integrations/vite/source-maps.test.ts b/integrations/vite/source-maps.test.ts index 0e2594690..fe26d9a7c 100644 --- a/integrations/vite/source-maps.test.ts +++ b/integrations/vite/source-maps.test.ts @@ -91,3 +91,67 @@ test( }) }, ) + +// https://github.com/tailwindlabs/tailwindcss/issues/19930 +test( + 'production build without Tailwind roots should not result in source map warnings', + { + fs: { + 'package.json': json` + { + "type": "module", + "dependencies": { + "@tailwindcss/vite": "workspace:^", + "tailwindcss": "workspace:^" + }, + "devDependencies": { + "vite": "^7" + } + } + `, + 'vite.config.ts': ts` + import { defineConfig } from 'vite' + import tailwindcss from '@tailwindcss/vite' + + export default defineConfig({ + plugins: [ + tailwindcss(), + { + name: 'inspect-source-map-chain', + enforce: 'pre', + transform(_, id) { + if (id.includes('.css')) { + // Force Rollup to collapse the sourcemap chain during this build. + this.getCombinedSourcemap() + } + }, + }, + ], + css: { + devSourcemap: true, + }, + build: { + sourcemap: true, + }, + }) + `, + 'index.html': html` + + +
Hello, world!
+ + `, + 'src/index.js': ts` import './index.css' `, + 'src/index.css': css` + body { + color: red; + } + `, + }, + }, + async ({ exec, expect }) => { + let output = await exec('pnpm vite build') + + expect(output).not.toContain('Sourcemap is likely to be incorrect') + }, +) diff --git a/packages/@tailwindcss-vite/src/index.ts b/packages/@tailwindcss-vite/src/index.ts index 1b71e2d14..a9c9ad5cf 100644 --- a/packages/@tailwindcss-vite/src/index.ts +++ b/packages/@tailwindcss-vite/src/index.ts @@ -241,7 +241,7 @@ export default function tailwindcss(opts: PluginOptions = {}): Plugin[] { let result = await root.generate(src, (file) => this.addWatchFile(file), I) if (!result) { roots.delete(id) - return src + return } DEBUG && I.end('[@tailwindcss/vite] Generate CSS (serve)') @@ -357,7 +357,7 @@ export default function tailwindcss(opts: PluginOptions = {}): Plugin[] { let result = await root.generate(src, (file) => this.addWatchFile(file), I) if (!result) { roots.delete(id) - return src + return } DEBUG && I.end('[@tailwindcss/vite] Generate CSS (build)')