PostCSS "Cannot find module 'autoprefixer'" - Fix in CI
PostCSS tried to load a plugin named in postcss.config.js and could not find it in node_modules. The config references a package that was never installed - or only installed locally and not declared as a dependency.
What this error means
The build fails with Cannot find module 'autoprefixer' (or tailwindcss, postcss-import, etc.) while loading the PostCSS config. It is deterministic - a missing dependency, not flake.
Failed to load PostCSS config: Cannot find module 'autoprefixer'
Require stack:
- /app/postcss.config.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
at postcss.config.js:3:5Common causes
Plugin not installed
The PostCSS config lists autoprefixer (or another plugin) that is not in package.json, so a clean npm ci does not provide it. Often it was installed ad hoc locally.
Installed as a transitive, not a direct dependency
The plugin was only present via hoisting from another package. A stricter install (or pnpm) does not expose it, so the config cannot resolve it.
How to fix it
Install the plugins your config references
Add every plugin named in postcss.config.js as a dev dependency.
npm install -D autoprefixer postcss tailwindcss
npm ls autoprefixerKeep the config and dependencies in sync
Only reference plugins you actually declare.
// postcss.config.js
module.exports = {
plugins: { tailwindcss: {}, autoprefixer: {} },
}How to prevent it
- Declare every PostCSS plugin in
devDependencies. - Install with
npm ciso CI matches the lockfile. - Do not rely on hoisted transitive plugins; require them directly.