Last updated: Apr 4, 2024
Reading timeยท3 min
The error "node-sass: Command failed" occurs for multiple reasons:
node-sass
module.node-sass
that is not compatible with your Node.js
version.node_modules
directory.error /node_modules/node-sass: Command failed. Command: node scripts/build.js 1837 error command failed 1837 error gyp ERR! not ok 1837 error gyp info it worked if it ends with ok Exit code: 1
The two most common ways to solve the error are to:
sass
package instead of the deprecated node-sass
module.node-sass
that is compatible with your version of
Node.js.The node-sass module has been deprecated, so the best way to solve the error is to use the sass module instead.
Open your terminal in your project's root directory and run the following commands.
# ๐๏ธ with NPM npm uninstall node-sass npm install sass --save-dev # ๐๏ธ or with YARN yarn remove node-sass yarn add sass --dev
The two commands uninstall the deprecated node-sass
module and install the
sass
module.
Try to restart your development server after running the commands.
If the error persists, try to delete your node_modules
and
package-lock.json (not
package.json
) files, rerun the npm install
command and restart your dev
server.
# ๐๏ธ (Windows) delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐๏ธ (macOS/Linux) delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐๏ธ clean npm cache npm cache clean --force npm install
Try to restart your development server after reinstalling your modules.
If you want to use the deprecated node-sass
module, make sure you have a
compatible node-sass
version installed for your version of Node.js.
If you'd rather use the deprecated node-sass
module, you have to install a
version of node-sass
that is compatible with your Node.js version.
The table in this section of the
node-sass
npm page shows which node-sass
version you should install for your
version of Node.js.
You can use the node --version
command to get your version of Node.js.
node --version
Here is part of the table.
NodeJS version | Supported node-sass version |
---|---|
Node 19 | 8.0+ |
Node 18 | 8.0+ |
Node 17 | 7.0+, <8.0 |
Node 16 | 6.0+ |
Node 15 | 5.0+, <7.0 |
Node 14 | 4.14+ |
Node 13 | 4.13+, <5.0 |
For example, if your Node.js version is 17, you would install version 7 of
node-sass
.
# ๐๏ธ if your Node.js version is 17 npm install node-sass@7 --save-dev # ๐๏ธ for YARN with Node.js version 17 yarn add node-sass@7 --dev
Your node-sass
version has to be compatible with your Node.js version,
otherwise, the error occurs.
node-sass
version in the devDependencies section of your package.json
file.If the error persists, try to delete your node_modules
and package-lock.json
(not package.json
) files, rerun the npm install
command and restart your dev
server.
# ๐๏ธ (Windows) delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐๏ธ (macOS/Linux) delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐๏ธ clean npm cache npm cache clean --force npm install
Try to restart your development server after reinstalling your modules.
If the error persists and you use "Create React app", try to update your version
of react-scripts
.
Open your terminal and run the following command to update your version of
react-scripts
.
# ๐๏ธ if you use npm npm install react-scripts@latest # ๐๏ธ if you use yarn yarn add react-scripts@latest
If the error persists, try to delete your node_modules
and package-lock.json
(not package.json
) files, rerun the npm install
and restart your dev server.
# ๐๏ธ (Windows) delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐๏ธ (macOS/Linux) delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐๏ธ clean npm cache npm cache clean --force npm install npm install react-scripts@latest
Try to restart your development server after updating your react-scripts
version.
To solve the error "node-sass: Command failed" error:
sass
package instead of the deprecated node-sass
module.node-sass
that is compatible with your
version of Node.js.node_modules
directory and your package-lock.json
files and
rerun npm install
.