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.
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
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-nesting3. 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