Maaz Zindani

Loading the index…

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

Your build asks for node-sass and cannot load it

ErrorError: Cannot find module 'node-sass'

Short answer

node-sass is end of life and its repository is archived, so installs on current Node.js often fail or never produce the binary. Replace it with the sass package (Dart Sass), remove node-sass from package.json, and reinstall. Code that calls the old render API should move to compile.

  • Applies to Node.js 22, npm 10, sass 1.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    See whether node-sass is listed in your dependencies and which Node.js you run. The node-sass project lists supported Node.js versions up to Node 20 only.

    node -v
    npm ls node-sass sass
  2. 2Match what you see, then jump to its fix

    1. 1Cannot find module 'node-sass' right after a fresh clone or a Node.js upgradeThe package was never installed, or the install step failed silentlyFix
    2. 2The error stays after installing sass, and the stack trace names a loader or a scriptThe tool still points at node-sass explicitlyFix
    3. 3sass.render or renderSync is used in your own build scriptCode calls the legacy render APIFix

What does the error look like?

  • Error: Cannot find module 'node-sass'
  • ERROR in Cannot find module 'node-sass'
  • Node Sass could not find a binding for your current environment

Cause 1 of 3

The package was never installed, or the install step failed silently

1Check

Look for node-sass in package.json and in the install log. node-sass downloads a prebuilt LibSass binary and falls back to compiling from source when that test fails.

grep -n "sass" package.json
ls node_modules | grep -i sass

2Fix

Do not repair node-sass. The project says it has reached end of life and recommends Dart Sass. Swap the dependency.

npm uninstall node-sass
npm install --save-dev sass

3Verify

npm now lists sass and no node-sass.

npm ls sass node-sass

Confirmed by github.com

Did this fix it?

Cause 2 of 3

The tool still points at node-sass explicitly

1Check

Search the config and scripts for the old name. A script such as node-sass in package.json, or an option that selects the implementation, keeps asking for it.

grep -rn "node-sass" package.json *.config.* 2>/dev/null

2Fix

Replace the command or option with the sass equivalent. The sass package ships its own command line, so a script like the one below works.

"scripts": {
  "build:css": "sass src/styles/main.scss dist/main.css"
}

3Verify

Run the script and confirm the CSS file is written.

npm run build:css && ls -l dist/main.css

Confirmed by sass-lang.com

Did this fix it?

Cause 3 of 3

Code calls the legacy render API

1Check

node-sass exposed render-style functions. The sass package still accepts them as a Legacy API, which is deprecated and kept only until sass 2.0.0.

grep -rn "renderSync\|\.render(" scripts/ build/ 2>/dev/null

2Fix

Use the current API, which returns the CSS directly.

const sass = require('sass');
const result = sass.compile('style.scss');
console.log(result.css);

3Verify

Run the script; the CSS prints without a deprecation warning.

node build-css.js

Confirmed by sass-lang.com

Did this fix it?

How do I stop it coming back?

  • Do not add node-sass to new projects; start with sass.
  • Pin the Node.js version in .nvmrc or engines so a laptop and the CI image install the same binaries.
  • Commit the lock file so every machine resolves the same sass version.

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

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

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