Your build asks for node-sass and cannot load it
Error: 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.
Fix it fast
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 sass2Match what you see, then jump to its fix
- 1
Cannot 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
The error stays after installing sass, and the stack trace names a loader or a scriptThe tool still points at node-sass explicitlyFix - 3
sass.render or renderSync is used in your own build scriptCode calls the legacy render APIFix
- 1
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 sass2Fix
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 sass3Verify
npm now lists sass and no node-sass.
npm ls sass node-sassConfirmed by github.com
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/null2Fix
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.cssConfirmed by sass-lang.com
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/null2Fix
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.jsConfirmed by sass-lang.com
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 fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fix