[Fix] error /node_modules/node-sass Command failed

The error “error /node_modules/node-sass: Command failed” is an error that is invoked whenever you are coding in node.js and using some incompatibility node modules. Given below is the snippet of the error, which I found when I was using vue.js:

error /var/www/html/vue-storefront/node_modules/node-sass: Command failed.

I would like to share with you the steps I took to fix the “error /node_modules/node-sass: Command failed” in your python file.

Why “error /node_modules/node-sass Command failed.” error is seen?

The error, “error /node_modules/node-sass: Command failed” is seen because you are using an old node-sass version as compared to your node version in your project file.

The detailed solution to fix the error “error /node_modules/node-sass: Command failed”, is given below.

How to fix the error, “error /node_modules/node-sass Command failed”?

For simple fix of the error, you can try to install the latest version of node-sass in accordance with your latest version of node which you are using in your project file.

To fix the error, “error /node_modules/node-sass: Command failed”, follow one of the methods given depending if you an yarn user or a npm user:

Method 1: If you are an npm user

To fix the error, “error /node_modules/node-sass: Command failed”, you will have to follow the below mentioned steps:

Step 1: In case your are in a Apple M1 Chip, you will have to run the terminal with Rosetta 2. Optional, as this is necessary only if you have your Node version installed with Rosetta

Step 2: You will have to check your node-sass version in the  package.json of your file and you will have to compare it with the following table:

NodeJSSupported node-sass versionNode Module
Node 166.0+93
Node 155.0+88
Node 144.14+83
Node 134.13+, <5.079
Node 124.12+72
Node 114.10+, <5.067
Node 104.9+, <6.064
Node 84.5.3+, <5.057
Node <8<5.0<57

Step 3: The next step is to check your Node version with the following command: node --version

Step 4: Then, you will have to install the Nodejs version according with your node-sass. In case you are using NVM, run: nvm use DESIRED_VERSION

Step 5: The next step would be to clean your old node_modules and delete the folder, or type the following command in your terminal: rm -rf node_modules

Step 6: Lastly you will have to run the following command: npm install

Method 2: If you a yarn user

To fix the error, “error /node_modules/node-sass: Command failed”, you will have to update your code by following steps given below:

You will have to upgrade your node-sass version to be the same as node version. With yarn you will have to run the below mentioned code:

yarn add node-sass

This should fix your error, “error /node_modules/node-sass: Command failed”.

Conclusion

To fix the error “error /node_modules/node-sass: Command failed”, you will have to install the latest version of node-sass in accordance with your latest version of node which you are using in your project file.