Next.js fails with Cannot find module 'tailwindcss'
Error: Cannot find module 'tailwindcss'Short answer
Next.js loads Tailwind through PostCSS, so the error means the package named in postcss.config is not installed where the build runs. Tailwind v4 needs tailwindcss, @tailwindcss/postcss and postcss, and a config that names the new plugin. On servers, a production install can skip devDependencies.
Fix it fast
1Find out which cause you have
See which Tailwind packages are installed, and which plugin your PostCSS config asks for.
npm ls tailwindcss @tailwindcss/postcss postcss cat postcss.config.*2Match what you see, then jump to its fix
- 1
npm ls shows (empty) or missing for tailwindcssThe Tailwind packages are not installedFix - 2
postcss.config lists tailwindcss: {} as a plugin, with postcss-import or autoprefixerA Tailwind v3 PostCSS config on a v4 installFix - 3
Works on your machine, fails in CI, Docker or on the host during next builddevDependencies were not installed on the server or in the imageFix
- 1
What does the error look like?
Error: Cannot find module 'tailwindcss'
Cause 1 of 3
The Tailwind packages are not installed
1Check
List what npm has installed in this project. All three packages must appear.
npm ls tailwindcss @tailwindcss/postcss postcss2Fix
Install the three packages for Tailwind v4 and import it from your global CSS.
npm install tailwindcss @tailwindcss/postcss postcss
/* app/globals.css */
@import "tailwindcss";3Verify
Start the dev server and open a page that uses a utility class.
npm run devConfirmed by tailwindcss.com
Cause 2 of 3
A Tailwind v3 PostCSS config on a v4 install
1Check
In v4 the PostCSS plugin moved to its own package, and imports and prefixing are handled for you.
cat postcss.config.mjs2Fix
Use only the new plugin, and replace the three @tailwind directives with one import.
// postcss.config.mjs
const config = {
plugins: {
"@tailwindcss/postcss": {},
},
};
export default config;3Verify
Restart the dev server after changing the config.
npm run devConfirmed by tailwindcss.com
Cause 3 of 3
devDependencies were not installed on the server or in the image
1Check
npm skips devDependencies when NODE_ENV is production or --omit=dev is used. If tailwindcss sits in devDependencies, the build step cannot find it.
npm config get omit2Fix
Install dev dependencies in the stage that runs next build, and only prune them afterwards.
npm ci --include=dev
npm run build3Verify
Run the same two commands in the failing environment.
npm ls tailwindcssConfirmed by docs.npmjs.com
How do I stop it coming back?
- Commit package-lock.json and install with npm ci in CI and in Docker.
- In a multi-stage Dockerfile, run the install and the build in the same stage.
- After a Tailwind major upgrade, follow the upgrade guide for the PostCSS config and the CSS import.
- Keep the three Tailwind packages together in package.json.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Web apps
Tailwind CSS 4 build fails on @apply in a Next.js project
Cannot apply unknown utility class
Tailwind 4 only knows its utilities in a stylesheet that imports Tailwind.
2 causes, each with a fixWeb apps
Tailwind build says the dark: class does not exist
dark: utilities work in markup but the build fails where @apply uses them in a separate CSS file
The build error means the CSS file being compiled cannot see your dark variant.
3 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Clerk cannot read its publishable key in a Next.js app
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY is undefined
Clerk reads NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY.
3 causes, each with a fixWeb apps
The shell cannot find create-next-app
command not found: create-next-app
create-next-app is not meant to be installed as a shell command.
2 causes, each with a fixWeb apps
ESLint fails with: Cannot find module 'next/babel'
ESLint stops on the first file with a Babel or parser error instead of listing lint results
next/babel is a Babel preset that ships inside the next package.
3 causes, each with a fix