How to Fix: bug npm run dev –turbo compiling material-tailwind error globals.css
Next.js Turbo is tripping over Material Tailwind because the CSS pipeline behaves differently under Turbopack than it does under the standard dev compiler, and that difference often surfaces first in globals.css.
Understanding the Root Cause
This issue usually appears when running npm run dev –turbo in a Next.js project that integrates @material-tailwind/react and Tailwind through a global stylesheet such as globals.css. The same project may compile correctly with the classic dev server but fail under Turbo because Turbopack is stricter about how CSS is imported, transformed, and scanned.
The core problem is typically one of these:
- Improper Tailwind content scanning: Material Tailwind components live in node_modules, and if Tailwind does not scan those files, required utility classes are missed or partially resolved.
- CSS layer ordering issues: If @tailwind base, @tailwind components, and @tailwind utilities are mixed with plugin-generated styles in the wrong order, Turbo may fail where webpack-based dev mode is more forgiving.
- Unsupported or fragile package parsing under Turbopack: Some third-party UI packages depend on build behavior that works in standard Next.js dev mode but exposes incompatibilities in Turbo.
- Incorrect Material Tailwind setup: Material Tailwind requires its helper integration in tailwind.config.js. If the wrapper is missing or incomplete, CSS generation can break, and the error often points back to globals.css even though the root cause is configuration.
In short, globals.css is usually the symptom, not the disease. The actual failure is often caused by Tailwind configuration, package scanning, or a current Turbopack compatibility gap with the library stack.
Step-by-Step Solution
The most reliable fix is to verify the full Tailwind and Material Tailwind integration, then reduce Turbo-specific friction.
1. Confirm your dependencies
Make sure your project has compatible versions of next, tailwindcss, postcss, autoprefixer, and @material-tailwind/react.
npm install next react react-dom tailwindcss postcss autoprefixer @material-tailwind/react
2. Configure Tailwind correctly for Material Tailwind
Your tailwind.config.js should include both your application files and Material Tailwind files in the content array, then wrap the config with withMT.
const withMT = require("@material-tailwind/react/utils/withMT");
module.exports = withMT({
content: [
"./app/**/*.{js,ts,jsx,tsx,mdx}",
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/**/*.{js,ts,jsx,tsx,mdx}",
"./node_modules/@material-tailwind/react/components/**/*.{js,ts,jsx,tsx}",
"./node_modules/@material-tailwind/react/theme/components/**/*.{js,ts,jsx,tsx}"
],
theme: {
extend: {}
},
plugins: []
});
This is critical because Material Tailwind generates and consumes utility classes from files outside your app source tree.
3. Keep globals.css minimal and correctly ordered
Your globals.css should start simple. Do not mix experimental imports or custom layer logic until the app compiles cleanly.
@tailwind base;
@tailwind components;
@tailwind utilities;
If your file contains extra @layer blocks, third-party imports, or custom plugin CSS, temporarily remove them and re-test with Turbo.
4. Verify postcss.config.js
Use the standard PostCSS setup expected by Tailwind.
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
5. Clear cached build artifacts
Old cache data can make this issue look inconsistent between normal dev mode and Turbo.
rm -rf .next node_modules package-lock.json
npm install
6. Test both dev modes explicitly
Update your scripts so you can compare behavior quickly.
{
"scripts": {
"dev": "next dev",
"dev:turbo": "next dev --turbo"
}
}
npm run dev
npm run dev:turbo
If standard dev mode works and Turbo still fails, the project is likely hitting a current Turbopack compatibility issue rather than a basic Tailwind misconfiguration.
7. Use the practical workaround if Turbo remains broken
If the goal is to keep developing immediately, use the non-Turbo dev server until the package combination stabilizes.
npm run dev
This is not just a fallback. For some third-party CSS ecosystems, it is the correct short-term production engineering decision while waiting for fixes in Next.js, Turbopack, or Material Tailwind.
8. Optional: move to a cleaner app structure
If the reproduction repository mixes app and pages patterns, old config, or duplicate CSS imports, simplify the structure so Tailwind is initialized once and globals.css is imported in only one root entry point.
// app/layout.tsx
import "./globals.css";
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
9. If needed, pin to known-stable versions
When a regression is introduced by a package update, pinning versions can isolate the break.
npm install next@latest tailwindcss@latest postcss@latest autoprefixer@latest @material-tailwind/react@latest
If latest still fails, test the last known working set from your lockfile or repository history.
Common Edge Cases
- Duplicate global CSS imports: Importing globals.css in more than one root file can trigger confusing build errors.
- Missing Material Tailwind wrapper: Using Tailwind without withMT often leads to missing styles or broken compilation paths.
- Wrong content globs: If your app uses a src directory or the app router and those paths are omitted, Tailwind may not generate required classes.
- Node version mismatch: Newer Next.js and Turbo builds can behave differently across Node versions. Test with a current LTS release.
- ESM/CommonJS config mismatch: If your project uses type: module, config files may need export default or renamed extensions.
- Third-party CSS imports inside component files: Turbo may react differently to package-level CSS import patterns than standard dev mode.
- Lockfile drift: Two machines with slightly different resolved versions may show the bug differently even with the same package.json.
FAQ
Why does it fail only with –turbo but work with normal npm run dev?
Turbopack does not always mirror webpack-based behavior exactly. Some CSS transforms, package resolution paths, and third-party integrations are stricter or still evolving, so a configuration that appears valid in classic dev mode can fail under Turbo.
Is globals.css actually broken?
Usually no. globals.css is often where the compiler notices the failure because that is where Tailwind directives are processed. The real issue is more commonly in Tailwind content configuration, Material Tailwind integration, or package compatibility with Turbo.
What is the safest fix if I need to keep shipping features today?
Use the standard next dev command, keep your Tailwind and Material Tailwind configuration correct, and avoid forcing –turbo until the dependency combination is confirmed stable. That gives you a working local environment without blocking feature delivery.
If you are debugging this in the linked reproduction, start by fixing tailwind.config.js, simplifying globals.css, clearing caches, and then comparing next dev versus next dev –turbo. In most cases, that sequence reveals whether the issue is a setup bug or a genuine Turbopack compatibility regression.