nextjs - 💡(How to fix) Fix Tailwind v4 persistent cache stuck on CSS syntax errors in Next.js (Turbopack & Monorepo) [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#90563Fetched 2026-04-08 00:19:51
View on GitHub
Comments
2
Participants
3
Timeline
13
Reactions
8
Timeline (top)
subscribed ×5labeled ×3commented ×2mentioned ×2

Error Message

  1. Introduce a syntax error in globals.css (e.g., remove a closing brace }).
  2. Next.js shows the compilation error.
  3. Fix the error in globals.css.
  4. Result: The error overlay stays in the browser. Refreshing or restarting the server does not help.
  5. This error is only disappear when i clear my .next folder or switch to run dev with --webpack flag
  6. Introduce a syntax error in the source file: packages/ui/globals.css.
  7. Result: The app crashes with a syntax error.
  8. Fix the error in packages/ui/globals.css.
  9. Observation: Even after restarting the dev server with either --turbo or --webpack, the error persists. The build process seems to be serving a cached version of the broken CSS file indefinitely. Next.js and the Tailwind v4 engine should invalidate the cache and re-parse the CSS files as soon as the file watcher detects a fix, clearing the error overlay without requiring a manual .next deletion. The error state is cached persistently. It appears the dependency graph (especially when involving @reference or cross-package imports) fails to trigger a clean rebuild after a hard syntax error occurs. I suspect this is a cache invalidation failure within Next.js's build engine. Vite demonstrates that the Tailwind v4 compiler can recover from these errors seamlessly. However, Next.js appears to fail in re-scanning or re-linking the @reference dependency once a hard syntax error has been cached, suggesting that the link between the CSS Module and the referenced file is being lost or stuck in an error state in the .next directory.

Root Cause

The issue is significantly worse in Monorepos because the file is outside the app's root, potentially confusing the invalidation logic.

Fix Action

Fix / Workaround

Temporary workaround: rm -rf .next && next dev.

Code Example

Next.js Version: 16.1.5
Tailwind CSS Version: 4.2.1
Node.js Version: 24.10.0
Package Manager: pnpm
Operating System: macOS / Windows
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/NapsterDinh/reproduce-turbopack-issue

To Reproduce

Case 1: Standard Root Structure (with Turbopack) Reproduce: https://codesandbox.io/p/live/222f9507-4106-469c-8172-d5b12d51b379

  1. Use Next.js 15 with Tailwind v4 and enable Turbopack (next dev --turbo).
  2. In a CSS Module (e.g., Button.module.css), use @reference "../../app/globals.css";.
  3. Introduce a syntax error in globals.css (e.g., remove a closing brace }).
  4. Next.js shows the compilation error.
  5. Fix the error in globals.css.
  6. Result: The error overlay stays in the browser. Refreshing or restarting the server does not help.
  7. This error is only disappear when i clear my .next folder or switch to run dev with --webpack flag

Case 2: Monorepo Structure (Turbopack & Webpack) - [More Severe] Reproduct: https://github.com/NapsterDinh/reproduce-turbopack-issue

  1. Setup a Monorepo where apps/web imports a CSS file from packages/ui/globals.css.
  2. In apps/web/app/globals.css, use @import "@repo/ui/globals.css";.
  3. Introduce a syntax error in the source file: packages/ui/globals.css.
  4. Result: The app crashes with a syntax error.
  5. Fix the error in packages/ui/globals.css.
  6. Observation: Even after restarting the dev server with either --turbo or --webpack, the error persists. The build process seems to be serving a cached version of the broken CSS file indefinitely.

Current vs. Expected behavior

Expected behavior Next.js and the Tailwind v4 engine should invalidate the cache and re-parse the CSS files as soon as the file watcher detects a fix, clearing the error overlay without requiring a manual .next deletion.

Actual behavior The error state is cached persistently. It appears the dependency graph (especially when involving @reference or cross-package imports) fails to trigger a clean rebuild after a hard syntax error occurs.

Provide environment information

Next.js Version: 16.1.5
Tailwind CSS Version: 4.2.1
Node.js Version: 24.10.0
Package Manager: pnpm
Operating System: macOS / Windows

Which area(s) are affected? (Select all that apply)

Turbopack, Webpack

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

The issue is significantly worse in Monorepos because the file is outside the app's root, potentially confusing the invalidation logic.

This bug completely breaks the development workflow, as any typo requires a full rm -rf .next and a cold start, which is time-consuming in large projects.

Temporary workaround: rm -rf .next && next dev.

Supplement: Comparison with Vite (HMR behavior) I suspect this is a cache invalidation failure within Next.js's build engine. Vite demonstrates that the Tailwind v4 compiler can recover from these errors seamlessly. However, Next.js appears to fail in re-scanning or re-linking the @reference dependency once a hard syntax error has been cached, suggesting that the link between the CSS Module and the referenced file is being lost or stuck in an error state in the .next directory.

extent analysis

Fix Plan

Solution Overview

The issue is caused by a persistent cache of the broken CSS file in the .next directory. To fix this, we need to invalidate the cache and re-parse the CSS files as soon as the file watcher detects a fix.

Configuration Changes

  • Update next.config.js to use the turbo configuration with the cache option set to false:

module.exports = { // ... turbo: { cache: false, }, };


#### Code Changes

*   In `globals.css`, use the `@apply` directive instead of `@reference` to import Tailwind classes:
    ```css
/* globals.css */
@tailwind base;
@tailwind components;
@tailwind utilities;

/* Use @apply instead of @reference */
.button {
    @apply bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded;
}

Infra / Dependency Fixes

  • Make sure to delete the .next directory after fixing the error in globals.css to ensure the cache is invalidated.

Temporary Workaround

  • Use the temporary workaround rm -rf .next && next dev to invalidate the cache and re-parse the CSS files.

Verification

  • After making the changes, run next dev and introduce a syntax error in globals.css.
  • Fix the error in globals.css and observe that the error overlay is cleared without requiring a manual .next deletion.
  • Verify that the build process serves the updated CSS file without caching the broken version.

Extra Tips

  • Make sure to update next.config.js to use the turbo configuration with the cache option set to false to ensure the cache is invalidated.
  • Use the @apply directive instead of @reference to import Tailwind classes to

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - 💡(How to fix) Fix Tailwind v4 persistent cache stuck on CSS syntax errors in Next.js (Turbopack & Monorepo) [2 comments, 3 participants]