Skip to content
Nilay Kabariya

Entry No.018·Fixes··3 min read

Fix: Failed to load PostCSS config (module is not defined) in Vite

Vite can't load your PostCSS config, sometimes one you didn't know existed. The three causes, how to tell which you have from the message, and what fixes each.

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

Tested on

Vite
8.3.0
PostCSS
8.5.28
Node
24.14.0
Tailwind CSS
4.3.3 (for the comparison)
OS
Windows 11 Pro
Contents
  1. Which one you have01
  2. 1. module is not defined in ES module scope02
  3. 2. A plugin in the config isn’t installed03
  4. 3. A config you didn’t know existed04
  5. If the error mentions Tailwind directly05
  6. What didn’t work06
  7. How this was tested07

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.

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: {} },
};

If the error mentions Tailwind directly

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

[postcss] It looks like you're trying to use `tailwindcss` directly as a PostCSS plugin.

That one has its own fix: trying to use tailwindcss directly as a PostCSS plugin. The quick way to tell them apart: 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.

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.

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

Useful? Pass it on:Post on XFollow @EmotionalMatter

Related entries

  1. No.009

    Fix: “trying to use tailwindcss directly as a PostCSS plugin”

    Tailwind v4 broke your PostCSS build. The two-line config change that fixes it, and the half-fix that keeps failing. Reproduced and verified.

    > Error: It looks like you're trying to use `tailwindcss` directly as a PostCSS

    FIXED1 min
  2. No.008

    Cannot apply unknown utility class border-border in Tailwind v4

    Two different causes trigger this Tailwind v4 error, and they need different fixes. How to tell which one you have. Both reproduced and fixed.

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

    FIXED2 min
  3. No.007

    Fix: 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

Post card · Newsletter

Get the next fix in your inbox.

One short email when a new entry is published. No spam, never shared, and you can leave any time.

— Nilay

or follow by RSSor on X

By subscribing you agree to the privacy note. One click to leave.

tip: paste the exact error text