Skip to content
Nilay Kabariya

Entry No.017·Fixes·Updated ·6 min read

Failed to load PostCSS config in Vite (and the Tailwind v4 error)

Vite can't load your PostCSS config, or Tailwind says to use @tailwindcss/postcss. The causes, how to tell them apart, and the tested fix for each.

What changed on Nov 9, 2026: Re-ran the Tailwind section on tailwindcss 4.3.5 and Vite 8.3.7; the error, the half-fix failure and both fixes were unchanged.

by Nilay#vite#tailwind#cssFIXED

The error, verbatim

Jump to the fix ↓
[plugin vite:css] C:/project/src/style.css
Failed to load PostCSS config: Failed to load PostCSS config (searchPath: C:/project): [ReferenceError] module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and 'C:\project\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
✓ Reproduced on Windows 11 Pro; Ubuntu (GitHub Actions)

The fix that worked

Switch the config to ES module syntax:

export default {
  plugins: {
    autoprefixer: {},
  },
};
Not it? Every cause, tested ↓

Tested on

Vite
8.3.0; re-tested on 8.3.5; Tailwind section on 8.3.7
PostCSS
8.5.28; 8.5.32 with Vite; postcss-cli 12.0.0 (Tailwind section)
Node
24.14.0; 24.22.1 and 24.22.2 on Ubuntu (GitHub Actions)
Tailwind CSS
4.3.3; re-tested on 4.3.5 (tailwindcss, @tailwindcss/postcss, @tailwindcss/vite)
OS
Windows 11 Pro; Ubuntu (GitHub Actions)

✓ Last re-run on GitHub Actions · see the run · all repros

Every version of this error starts with the same words, and the part that tells you the cause comes after the second colon. Read that part first. If your message instead says It looks like you're trying to use tailwindcss directly as a PostCSS plugin, skip to that section.

Which one you have

After Failed to load PostCSS config (searchPath: …): Cause Section
module is not defined in ES module scope CommonJS syntax in an ES module project 1
Cannot find module 'something' and your config lists it A plugin in the config isn’t installed 2
Cannot find module 'something' and you never used it, or have no config Vite found a different config in a parent folder 3

1. module is not defined in ES module scope

Your package.json has "type": "module", so a .js config is an ES module, and module.exports doesn’t exist there. Newer projects often set "type": "module", while many older guides and plugin READMEs still show module.exports.

Either switch the file to ES module syntax:

// postcss.config.js
export default {
  plugins: {
    autoprefixer: {},
  },
};

or keep the CommonJS syntax and rename the file to postcss.config.cjs.

2. A plugin in the config isn’t installed

Failed to load PostCSS config (searchPath: C:/project): [Error] Loading PostCSS Plugin failed: Cannot find module 'postcss-nesting'

The config names a plugin that isn’t in node_modules: copied from another project, or removed from package.json without cleaning up the config.

Install it, or delete that line from the config if you don’t need it:

npm i -D postcss-nesting

3. A config you didn’t know existed

This is the one that costs people an afternoon. My project had no PostCSS config and had never used Tailwind, and the build failed anyway:

Failed to load PostCSS config (searchPath: C:/project/app): [Error] Loading PostCSS Plugin failed: Cannot find module 'tailwindcss'

The message names your project folder as the search path. It doesn’t say where the config it loaded actually came from. When a project has no config, Vite keeps searching upward through parent folders, and it had found an old postcss.config.js one level up, in a folder that held a previous project.

It happens with configs left in a home directory, a monorepo root, or a folder you unzip projects into.

Find it. This walks up from the current folder and prints every PostCSS config it passes, on Windows, macOS and Linux:

node -e "const fs=require('fs'),p=require('path');let d=process.cwd();for(;;){for(const f of fs.readdirSync(d))if(/^(postcss\.config\.(c|m)?(js|ts)|\.postcssrc(\.(json|ya?ml|js|cjs|mjs))?)$/.test(f))console.log(p.join(d,f));const u=p.dirname(d);if(u===d)break;d=u}"

Then either delete or rename that file, or, if you can’t touch it (a shared folder, a monorepo root), tell Vite not to look for one at all:

// vite.config.js
export default {
  css: { postcss: {} },
};

It looks like you’re trying to use tailwindcss directly as a PostCSS plugin

If Tailwind v4 is installed and your config says tailwindcss: {}, the error is different and isn’t wrapped in “Failed to load PostCSS config”. The full message:

Error: It looks like you're trying to use `tailwindcss` directly as a PostCSS
plugin. The PostCSS plugin has moved to a separate package, so to continue
using Tailwind CSS with PostCSS you'll need to install `@tailwindcss/postcss`
and update your PostCSS configuration.

The quick way to tell it apart from case 3: Cannot find module 'tailwindcss' means Tailwind isn’t installed where the config expects it; “trying to use tailwindcss directly” means it is installed, but it’s v4.

With Vite 8.3.5, Tailwind 4.3.3 and the old tailwindcss: {} line in postcss.config.js, vite build failed with:

error during build:
[plugin vite:css] src/style.css:undefined:NaN
Error: [postcss] It looks like you're trying to use `tailwindcss` directly as a PostCSS plugin.

The dev server didn’t fail at startup. It printed the same message the first time the CSS file was requested:

[vite] Internal server error: [postcss] It looks like you're trying to use `tailwindcss` directly as a PostCSS plugin.
  Plugin: vite:css

Up to v3, the tailwindcss package was the PostCSS plugin, so every guide told you to write tailwindcss: {} in postcss.config.js. In v4 the plugin lives in its own package, @tailwindcss/postcss, and the main package throws this error on purpose when PostCSS tries to load it the old way. It usually shows up when a project upgrades to v4, or when you follow a v3 tutorial but npm install gives you v4.

Install the new plugin package:

npm install -D @tailwindcss/postcss

Then change the plugin name in postcss.config.js (or .mjs / .cjs) from tailwindcss to @tailwindcss/postcss, using the syntax that matches your project (see section 1):

export default {
  plugins: {
    "@tailwindcss/postcss": {},
  },
};

Your CSS entry file should import Tailwind the v4 way:

@import "tailwindcss";

In a Vite project you can also drop PostCSS for Tailwind and use its Vite plugin. Delete postcss.config.js (or just its Tailwind line), install @tailwindcss/vite, and add it to vite.config.js:

import tailwindcss from '@tailwindcss/vite';
export default { plugins: [tailwindcss()] };

You can keep autoprefixer: with autoprefixer: {} left in the config, the build still succeeded. Tailwind v4 adds vendor prefixes itself, so you can also remove it from the config and uninstall it.

What didn’t work

How this was tested

A fresh Vite 8.3.0 project with "type": "module" on Node 24.14.0, built with vite build. Each cause was produced on purpose: a module.exports config, a config naming an uninstalled plugin, and an app with no config under a parent folder holding an old Tailwind config. Tailwind 4.3.3 was installed only for the last comparison. Every error and every fix above is the real build output.

November 2, 2026: cases 1 and 2, the .cjs rename that didn’t work, and the finder one-liner were re-run on Vite 8.3.5 and PostCSS 8.5.32 on GitHub Actions ubuntu-latest (Node 24.22.1); every result matched. Case 3 and its inline css.postcss fix were re-run on Windows 11 with Vite 8.3.0 and 8.3.5 (Node 24.21.0) and matched; on Linux the stray parent config was not picked up. The script and output are public.

The Tailwind section was first tested with tailwindcss and @tailwindcss/postcss 4.3.3, PostCSS 8.5.28 with postcss-cli 12.0.0, and Vite 8.3.5 with @tailwindcss/vite 4.3.3, on Node 24.14.0 / Windows 11 Pro. On November 2, 2026 it was re-run on GitHub Actions ubuntu-latest (Node 24.22.1) with tailwindcss 4.3.3, PostCSS 8.5.32 and Vite 8.3.5: tailwindcss: {} failed in postcss-cli and in vite build ([plugin vite:css]), installing @tailwindcss/postcss without changing the config failed the same way, and both fixes built with text-red-500 in the CSS. On November 10, 2026 the same script ran again on the newer releases it installed, tailwindcss 4.3.5 and Vite 8.3.7 (PostCSS 8.5.32, Node 24.22.2): the error text, the half-fix failure and both fixes came out the same. That script and output are public too.

— N.K., end of entry No.017

Useful? Pass it on:Post on XFollow @EmotionalMatter

Related entries

  1. No.008

    Cannot apply unknown utility class border-border in Tailwind v4

    Three causes trigger this Tailwind v4 error, each with its own fix: custom colours, CSS modules and Vue/Svelte styles, and v3 classes. All reproduced.

    > Error: Cannot apply unknown utility class `border-border`

    FIXED3 min
  2. No.007

    npx tailwindcss init: "could not determine executable to run"

    npx tailwindcss init fails on a fresh install. Why Tailwind v4 does this, two fixes that work, and the command that fails silently. Reproduced.

    > $ npx tailwindcss init

    FIXED2 min
  3. No.108

    sh: vite: command not found on Linux, macOS, CI and Docker

    sh: vite: command not found in CI, Docker or a Linux shell: six causes tested on Ubuntu and macOS, the exact message each one prints, and which fix worked.

    > > vite build

    FIXED4 min

tip: paste the exact error text