tailwindcss: Fix : Error with lightningcss when using Tailwind CSS v4 with Next.js 15.2.1 and Node.js 20.18.3
Getting Error with lightningcss when using Tailwind CSS v4 with Next.js 15.2.1 and Node.js 20.18.3 using create-next-app@latest . --use-pnpm
version of Tailwind CSS
v4.0.12 (via @tailwindcss/postcss)
build tool framework
Next.js 15.2.1 with Turbopack
version of Node.js
v20.18.3
browser
N/A (Build error)
** operating system **
Windows 10
Repo URL https://github.com/abhishekkumar35/blogcodeabode also attached terminal messages in a saparate md file name terminalmessage.md(can be found in repo)
- Create a new Next.js project with Tailwind CSS:
(Select Yes for Tailwind CSS, TypeScript, ESLint, App Router, and Turbopack)npx create-next-app@latest blogcodeabode --use-pnpm - Run the development server:
pnpm dev
Describe your issue
When running a Next.js 15.2.1 application with Tailwind CSS v4, I’m getting the following error related to lightningcss:
⨯ ./app/globals.css
- D:\codebase\blogcodeabode\node_modules\.pnpm\lightningcss@1.29.2\node_modules\lightningcss\node\index.js
- D:\codebase\blogcodeabode\node_modules\.pnpm\@tailwindcss+postcss@4.0.12\node_modules\@tailwindcss\postcss\dist\index.js
- D:\codebase\blogcodeabode\.next\build\chunks\[turbopack]_runtime.js
- D:\codebase\blogcodeabode\.next\transform.js
[at Module._resolveFilename (node:internal/modules/cjs/loader:1225:15)]
[at Module._load (node:internal/modules/cjs/loader:1051:27)]
[at Module.require (node:internal/modules/cjs/loader:1311:19)]
[at require (node:internal/modules/helpers:179:18)]
[at Object.<anonymous> (D:\codebase\blogcodeabode\node_modules\.pnpm\lightningcss@1.29.2\node_modules\lightningcss\node\index.js:22:22)]
[at Module._compile (node:internal/modules/cjs/loader:1469:14)]
[at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)]
[at Module.load (node:internal/modules/cjs/loader:1288:32)]
[at Module._load (node:internal/modules/cjs/loader:1104:12)]
[at Module.require (node:internal/modules/cjs/loader:1311:19)]
The application fails to compile CSS and returns a 500 error. This appears to be an issue with the lightningcss dependency that Tailwind CSS v4 uses.
My package.json dependencies:
{
"dependencies": {
"react": "^19.0.0",
"react-dom": "^19.0.0",
"next": "15.2.1"
},
"devDependencies": {
"typescript": "^5",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"@tailwindcss/postcss": "^4",
"tailwindcss": "^4",
"eslint": "^9",
"eslint-config-next": "15.2.1",
"@eslint/eslintrc": "^3"
}
}
the application is expected to compile and run without errors.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 21 (1 by maintainers)
Commits related to this issue
- fix: https://github.com/tailwindlabs/tailwindcss/issues/17046 — committed to KaiserRuben/TokenLense by KaiserRuben 2 years ago
✅ Solution for “Cannot find module
lightningcss.win32-x64-msvc.node” on WindowsIf you’re on Windows and encountering this error:
It may be caused by a misconfigured
.npmrcfile whereos = "linux"is incorrectly set. This causesnpmto install binaries for the wrong platform, breaking native modules likelightningcss.🔧 Steps to Fix
Run the following in your project root:
If you see:
This is the root cause.
osSettingRun this command to fix it:
Alternatively, open this file:
And manually delete the line:
Once the config is fixed, clean your project:
Then restart your dev server:
✅ Why This Works
When
os = "linux"is set in.npmrcon a Windows machine,npmfetches Linux-specific binaries, which don’t work on Windows. Native modules likelightningcssrely on platform-specific.nodefiles, so they fail to load if the wrong binary is used.✅ Fixed:
Error: Cannot find module '../lightningcss.win32-x64-msvc.node'in Next.jsI had the same problem. I tried all the suggested solutions and nothing worked.
I eventually got it to start running by making the following changes:
🔧 1. Updated
postcss.config.mjsBefore:
After:
🧱 2. Added
tailwind.config.jsIf it was missing, I added a basic
tailwind.config.jsto support the updated config.🎨 3. Updated CSS imports
Before:
After:
📦 4. Fixed devDependencies
@tailwindcss/postcsstailwindcss,autoprefixer, andpostcssThis is essentially the older configuration for Tailwind CSS and PostCSS.
I guess the root issue was with the “@tailwindcss/postcss” plugin.
I think this is fixed for Next 15.2.2, just upgraded it and the error disappeared