Skip to content
Latchkey

PostCSS "Cannot find module 'postcss'" - Fix in CI

Something tried to load postcss and it is not installed. postcss is a peer dependency of postcss-loader, autoprefixer, and Tailwind - you must install it directly.

What this error means

The build fails with Cannot find module 'postcss', typically from postcss-loader or a PostCSS plugin during CSS processing.

node
Error: Cannot find module 'postcss'
Require stack:
- /app/node_modules/postcss-loader/dist/index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader)

Common causes

postcss not a direct dependency

Plugins and loaders declare postcss as a peer dependency, so it does not get installed transitively in strict setups.

devDependencies pruned

A production-only install removed postcss before the build ran.

How to fix it

Install postcss directly

  1. Add postcss as a dependency and commit the lockfile.
Terminal
npm install -D postcss

Keep dev deps during the build job

  1. Run a full npm ci before the build; only prune for the runtime image.
Terminal
npm ci   # do not pass --omit=dev before building CSS

How to prevent it

  • Install peer dependencies (postcss, autoprefixer) explicitly rather than relying on hoisting.
  • Separate build-time and runtime install steps in CI.

Frequently asked questions

What causes "Cannot find 'postcss'"?
Plugins and loaders declare postcss as a peer dependency, so it does not get installed transitively in strict setups.
How do I fix Cannot find 'postcss'?
Install postcss directly

Related guides

References

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