Skip to content
Latchkey

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.

node
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

  1. Add sass as a dependency.
  2. Commit the updated lockfile so CI installs it deterministically.
Terminal
npm install -D sass

Install dev dependencies for the build step

  1. If you build in CI, do not omit dev dependencies before the build runs.
Terminal
npm ci   # installs devDependencies too; avoid --omit=dev before build

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

Frequently asked questions

What causes "Cannot find 'sass'"?
sass-loader lists sass as a peer, not a hard dependency, so you must install sass yourself.
How do I fix Cannot find 'sass'?
Install sass and commit the lockfile

Related guides

References

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