Sass "Cannot find module 'sass'" - Fix in CI
A loader (or your script) tried to require('sass') and it is not in node_modules. Usually sass is a build-only dependency that a production-only install skipped, or it was never added.
What this error means
The build throws Error: Cannot find module 'sass', frequently from sass-loader. It is deterministic and re-running does not help.
Error: Cannot find module 'sass'
Require stack:
- /app/node_modules/sass-loader/dist/index.js
at Module._resolveFilename (node:internal/modules/cjs/loader)Common causes
sass missing from dependencies
sass-loader lists sass as a peer, not a hard dependency, so you must install sass yourself.
Production-only install dropped it
npm ci --omit=dev (or NODE_ENV=production) skips devDependencies, so a sass listed under devDependencies is absent at build time.
How to fix it
Install sass and commit the lockfile
- Add sass as a dependency.
- Commit the updated lockfile so CI installs it deterministically.
npm install -D sassInstall dev dependencies for the build step
- If you build in CI, do not omit dev dependencies before the build runs.
npm ci # installs devDependencies too; avoid --omit=dev before buildHow to prevent it
- Keep build-time tools available during the build job; only prune dev deps for the runtime artifact.
- Pin sass and sass-loader to compatible versions.