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)

  1. Create a new Next.js project with Tailwind CSS:
    npx create-next-app@latest blogcodeabode --use-pnpm
    
    (Select Yes for Tailwind CSS, TypeScript, ESLint, App Router, and Turbopack)
  2. 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

Most upvoted comments

✅ Solution for “Cannot find module lightningcss.win32-x64-msvc.node” on Windows

If you’re on Windows and encountering this error:

Error: Cannot find module '../lightningcss.win32-x64-msvc.node'

It may be caused by a misconfigured .npmrc file where os = "linux" is incorrectly set. This causes npm to install binaries for the wrong platform, breaking native modules like lightningcss.


🔧 Steps to Fix

  1. Check Your npm Configuration

Run the following in your project root:

npm config list

If you see:

os = "linux"

This is the root cause.


  1. Remove the Incorrect os Setting

Run this command to fix it:

npm config delete os

Alternatively, open this file:

C:\Users\<your-username>\.npmrc

And manually delete the line:

os = "linux"

  1. Clean and Reinstall Dependencies

Once the config is fixed, clean your project:

rm -rf node_modules package-lock.json .next
npm cache clean --force
npm install

Then restart your dev server:

npm run dev

✅ Why This Works

When os = "linux" is set in .npmrc on a Windows machine, npm fetches Linux-specific binaries, which don’t work on Windows. Native modules like lightningcss rely on platform-specific .node files, so they fail to load if the wrong binary is used.

✅ Fixed: Error: Cannot find module '../lightningcss.win32-x64-msvc.node' in Next.js

I 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.mjs

Before:

const config = {
  plugins: ["@tailwindcss/postcss"],
};

export default config;

After:

const config = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
};

export default config;

🧱 2. Added tailwind.config.js

If it was missing, I added a basic tailwind.config.js to support the updated config.

/** @type {import('tailwindcss').Config} */
export default {
  content: [
    "./pages/**/*.{js,ts,jsx,tsx}",
    "./components/**/*.{js,ts,jsx,tsx}"
  ],
  theme: {
    extend: {},
  },
  plugins: [],
};

🎨 3. Updated CSS imports

Before:

@import "tailwindcss";

After:

@tailwind base;
@tailwind components;
@tailwind utilities;

📦 4. Fixed devDependencies

  • Removed: @tailwindcss/postcss
  • Added: tailwindcss, autoprefixer, and postcss
npm install -D tailwindcss postcss autoprefixer

This 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