npm install stops at node-sass with 'Command failed'
error /project/node_modules/node-sass: Command failed.Short answer
node-sass downloads a prebuilt binary that matches your Node.js version. When none exists, or the download is blocked, it compiles from source and fails without a compiler. The project is end of life, so the lasting fix is to replace node-sass with the sass package. A binary mirror or build tools only keep an old install alive.
Fix it fast
1Find out which cause you have
Compare your Node.js version with the node-sass version your lock file resolved. The node-sass README lists which node-sass releases support which Node.js line.
node -v npm ls node-sass2Match what you see, then jump to its fix
- 1
The failure starts right after a Node.js upgrade, and the node-sass version in the lock file is older than the table allows.Your Node.js version is newer than the node-sass release supportsFix - 2
The install log shows a failed download, or the machine sits behind a proxy or has no internet access during install.The prebuilt binary cannot be downloadedFix - 3
gyp lines in the log after the download step, for example a Python or Visual Studio message.It fell back to building from source and the build tools are missingFix
- 1
What does the error look like?
error /project/node_modules/node-sass: Command failed.npm install or yarn install exits with an error in the node-sass install script
Cause 1 of 3
Your Node.js version is newer than the node-sass release supports
1Check
The README table pairs each Node.js line with the node-sass versions that ship binaries for it (for example Node 20 needs node-sass 9.0 or newer). Anything outside the table has no prebuilt binary.
node -v
npm ls node-sass2Fix
node-sass receives no more releases, so do not chase a newer version. Swap it for the sass package, which the Sass team names as the replacement and which exposes the same JavaScript API.
npm uninstall node-sass
npm install --save-dev sass3Verify
A clean install and a build both finish.
rm -rf node_modules
npm install
npm run buildConfirmed by sass-lang.com
Cause 2 of 3
The prebuilt binary cannot be downloaded
1Check
node-sass fetches its binary from a download site on install. If that fails it falls back to building from source.
npm install node-sass --loglevel verbose2Fix
Point the installer at a mirror that holds the binaries. The README allows an environment variable, an .npmrc entry or a command-line flag. Use this only to keep an old project running until you move to sass.
export SASS_BINARY_SITE=http://example.com/
npm install node-sass3Verify
The install completes without compiling anything.
npm ls node-sassConfirmed by github.com
Cause 3 of 3
It fell back to building from source and the build tools are missing
1Check
A source build needs node-gyp and its prerequisites. On Windows that means Python and the Visual Studio C++ workload.
npm install node-sass --loglevel verbose2Fix
Install what the node-gyp README lists for your operating system, or avoid the build altogether by moving to sass as in the first cause.
npm install --save-dev sass3Verify
The install log has no gyp lines.
npm installConfirmed by github.com
How do I stop it coming back?
- Start new projects on sass, not node-sass.
- Pin the Node.js version in .nvmrc or the engines field so every machine installs the same binaries.
- Commit the lock file so a fresh install resolves the same versions.
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
Your build asks for node-sass and cannot load it
ERROR in Cannot find module 'node-sass'
node-sass is end of life and its repository is archived, so installs on current Node.js often fail or never produce the binary.
3 causes, each with a fixBack end
npm install stops while building a native module with node-gyp
Could not find any Python installation to use
node-gyp compiles native add-ons, so it needs a supported Python and a C/C++ compiler.
3 causes, each with a fixBack end
ng serve says it cannot determine the project or target
Cannot determine project for command.
The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.
3 causes, each with a fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
ng serve cannot find the dev-server builder package
Could not find the implementation for builder @angular/build:dev-server
The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.
3 causes, each with a fix