Skip to content
Latchkey

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.

build output
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:5

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

Terminal
npm install -D autoprefixer postcss tailwindcss
npm ls autoprefixer

Keep the config and dependencies in sync

Only reference plugins you actually declare.

postcss.config.js
// postcss.config.js
module.exports = {
  plugins: { tailwindcss: {}, autoprefixer: {} },
}

How to prevent it

  • Declare every PostCSS plugin in devDependencies.
  • Install with npm ci so CI matches the lockfile.
  • Do not rely on hoisted transitive plugins; require them directly.

Frequently asked questions

What causes ""Cannot find module 'autoprefixer'""?
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.
How do I fix "Cannot find module 'autoprefixer'"?
Add every plugin named in postcss.config.js as a dev dependency.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card