Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Vite cannot find the sass preprocessor you import

ErrorInternal server error: Preprocessor dependency "sass" not found. Did you install it?

Short answer

Vite compiles .scss and .sass files but does not ship the compiler. Install sass-embedded or sass in the project that runs Vite, as a dev dependency. If it works locally and fails in CI or a Docker build, the install skipped devDependencies, so include them for the build.

  • Applies to Vite 7 and 8, Node.js 22, npm 11
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check whether a sass package is installed in the folder that runs Vite, and whether your install step leaves out dev dependencies.

    npm ls sass sass-embedded
    echo "NODE_ENV=$NODE_ENV"
  2. 2Match what you see, then jump to its fix

    1. 1npm ls prints (empty) for both sass and sass-embeddedNo Sass compiler is installedFix
    2. 2Local dev works, CI or the Docker build fails, and NODE_ENV is production during npm installThe build install leaves out devDependenciesFix

What does the error look like?

  • Internal server error: Preprocessor dependency "sass" not found. Did you install it?
  • The same message during vite build in CI or Docker, although it works on your machine

Cause 1 of 2

No Sass compiler is installed

1Check

The Vite docs say .scss, .sass, .less and .styl files work without Vite plugins, but the pre-processor itself must be installed. For Sass that is sass-embedded or sass.

npm ls sass sass-embedded

2Fix

Install one of them as a dev dependency. Vite uses sass-embedded when it is present and falls back to sass; the docs recommend sass-embedded for speed.

npm add -D sass-embedded

3Verify

Restart the dev server or run the build, and open a page that imports the .scss file.

npm run build

Confirmed by vite.dev

Did this fix it?

Cause 2 of 2

The build install leaves out devDependencies

1Check

npm omits dev dependencies by default when NODE_ENV is production, and sass was added with -D.

grep -n -B1 -A3 devDependencies package.json
echo "$NODE_ENV"

2Fix

Run the install for the build stage with dev dependencies included, then prune or copy only the build output into the final image.

npm ci --include=dev
npm run build

3Verify

The build step prints the finished bundle list instead of the sass error.

npm run build

Confirmed by docs.npmjs.com

Did this fix it?

How do I stop it coming back?

  • Add the Sass compiler as soon as the first .scss file is added to the project.
  • Run the same install and build commands in CI that you run locally, with dev dependencies included.
  • In monorepos, install the compiler in the package that owns vite.config, not in the repository root only.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.