Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

npm install stops at node-sass with 'Command failed'

Errorerror /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.

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

Fix it fast

  1. 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-sass
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2The 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. 3gyp 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

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-sass

2Fix

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 sass

3Verify

A clean install and a build both finish.

rm -rf node_modules
npm install
npm run build

Confirmed by sass-lang.com

Did this fix it?

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 verbose

2Fix

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-sass

3Verify

The install completes without compiling anything.

npm ls node-sass

Confirmed by github.com

Did this fix it?

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 verbose

2Fix

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 sass

3Verify

The install log has no gyp lines.

npm install

Confirmed by github.com

Did this fix it?

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 fix

Back 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 fix

Back 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

Next step

Want this handled for good?

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