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.
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
- Add postcss as a dependency and commit the lockfile.
npm install -D postcssKeep dev deps during the build job
- Run a full
npm cibefore the build; only prune for the runtime image.
npm ci # do not pass --omit=dev before building CSSHow to prevent it
- Install peer dependencies (postcss, autoprefixer) explicitly rather than relying on hoisting.
- Separate build-time and runtime install steps in CI.