294

Config: macOS High Sierra, version 10.13.2, node:v8.1.2 npm:5.0.3 When I run npm start in my angularjs project I get this error:

ERROR in Cannot find module 'node-sass'

After this I run:

npm i node-sass

Now I get this error:

gyp: No Xcode or CLT version detected!
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1

Why won't npm install node-sass? How can I install node-sass?

bier hier
  • 20,970
  • 42
  • 97
  • 166

34 Answers34

541

Here's the solution:

sudo npm install --save-dev  --unsafe-perm node-sass

Enjoy!

Edited to explain the options (from comments):

--save-dev is used so that your app is able to find the module in local node_modules. --save-dev adds package to devDependencies in package.json. --unsafe--perm is used to run install scripts as root. To avoid sudo, use nvm instead. --unsafe--perm is really not needed as sudo is already mentioned. So the command basically air tights the script to install node-sass at any cost.

rmcsharry
  • 5,363
  • 6
  • 65
  • 108
Alex Onozor
  • 6,841
  • 1
  • 22
  • 26
  • 41
    This worked, but if someone could add to the answer on why this worked and the simple `npm install node-sass` did not work it would be instructive. – Be Kind To New Users Jan 14 '19 at 05:06
  • All I needed was `sudo npm install --unsafe-perm` and it worked for me because I had EACCES issues. – James C Apr 08 '19 at 15:06
  • 24
    all I need to was install node-sass in **dev dependencies** `npm install --save-dev node-sass` – Subhash Diwakar Apr 15 '19 at 07:03
  • 3
    This worked for me. I started getting this issue when I installed node 12 (as I started a new angular project in Angular 8). My angular 6 app would no longer build and throw the error about node-sass. All fixed :) – punkologist Jun 10 '19 at 21:50
  • 2
    I'm still not clear WHY or HOW this solution works. How does adding to "devDependencies" solve the problem? How will it NOT cause problems when deployed? Side-Note: I'm very new to Angular and front end programming. Any clear explanation would be very useful! Many thanks! – Amogh Natu Jun 13 '19 at 15:32
  • 2
    @AmoghNatu just running `npm install node-sass` will install the node-sass module. Adding `--save-dev` will also add the dependency to `package.json`. Adding `--unsafe-perm` allows npm to download node-sass binary (considered unsafe) directly to your project. – Irman Ahmad Jul 01 '19 at 10:24
  • This is funny, because I had exactly the same issue in the same project in 2 computers, and this solution worked in one computer and didn't work in the other – Sarah Aug 08 '20 at 11:09
  • 1
    Solution worked for me is `npm install node-sass@latest` – El7or May 16 '21 at 12:22
  • Tried and got: `'sudo' is not recognized as an internal or external command, operable program or batch file.` – menoktaokan Aug 17 '21 at 06:24
  • I bet you were running `sudo` on Windows... – kkuilla Dec 10 '21 at 14:34
  • sometimes you may get incompatibility errors while doing this operation - if you do - then follow this - https://stackoverflow.com/questions/70281346/node-sass-version-7-0-0-is-incompatible-with-4-0-0-5-0-0-6-0-0 – abhijat_saxena Dec 15 '21 at 15:00
115
  1. This error is for node-sass is not present ... to solve this just you want to run following command

npm install node-sass

alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46
kedar kokil
  • 1,383
  • 1
  • 8
  • 5
  • 47
    add as devDependencies ```npm install --save-dev node-sass```. – Ashok R Sep 16 '18 at 09:01
  • 7
    Doesn't help. I've already installed node-sass a dozen times (which wasn't easy), but it still fails. Node-sass is clearly a problem. – mcv Nov 06 '18 at 15:25
  • 2
    @AshokR Can you please elaborate on exactly WHY adding it as devDependencies solves the problem? How will it NOT fail when deployed to prod? – Amogh Natu Jun 13 '19 at 15:36
43

According to node-sass github page, supported node.js version vary release by release.

https://github.com/sass/node-sass

enter image description here

Example: Check the version of node you are running.

node -v
-> v12.0.0

you need node-sass v4.12+. so you can

npm install node-sass@4.12.0

or if 4.12.0 is the latest

npm install node-sass@latest

(npm install node-sass will install the latest version in many cases, but remember that it does not always install the latest(in this example 4.12.0) if dependency in package.json is written like ^3.0.0, ~4.11.0) What's the difference between tilde(~) and caret(^) in package.json?

Lastly, using sudo with npm is not a good practice. Please refer to this article. https://medium.com/@ExplosionPills/dont-use-sudo-with-npm-still-66e609f5f92

ohkts11
  • 2,581
  • 2
  • 21
  • 17
28

Doing npm uninstall node-sass and then npm i node-sass did not work for me.

Solution worked for me is npm install --save-dev node-sass.

Happy Coding..

SendETHToThisAddress
  • 2,756
  • 7
  • 29
  • 54
Bandham Manikanta
  • 1,858
  • 21
  • 21
23

Run:

npm rebuild node-sass --force              

and it'll work fine.

Marco Altieri
  • 3,726
  • 2
  • 33
  • 47
PENG ZHU
  • 275
  • 2
  • 6
7

It worked for me...

sudo npm rebuild node-sass --force
Vibhu kumar
  • 386
  • 3
  • 8
7

node-sass is not being installed and it can be one of many reasons

You have not installed it

npm install node-sass --save-dev

You are having a permissions error

sudo npm install --save-dev  --unsafe-perm node-sass

You had a memory issue because it tried to make it (build from c code in your platform),this applies to some platforms and node versions

node --max_old_space_size=8000 $(which npm) install node-sass --save-dev

Your node and npm versions are not compatible,which most probably generated a failure in the build process,

In this case use n or nvm to make sure you have the same version in the new and original environment, the one where it did work, as this is usually by using different versions in different environments

Elangovan
  • 3,469
  • 4
  • 31
  • 38
zardilior
  • 2,810
  • 25
  • 30
6

This is what worked for me. I first uninstall node-sass. Then install it back.

npm uninstall node-sass
npm install --save-dev node-sass

Olumide Ayeni
  • 179
  • 2
  • 7
5

In my case I also had to perform:

npm install sass-loader

To fix the problem

Rob
  • 10,004
  • 5
  • 61
  • 91
5

It failed for me because I was using the latest version of node (12.7.0) I then had to explicitly install the latest version of node-sass with:

npm install node-sass@4.12.0

Andreas Gassmann
  • 6,334
  • 7
  • 32
  • 45
4

I have fix this problem without installing node-sass by this command:

npm install node-sass@4.12.0 --no-save --unsafe-perm
Joffrey Hernandez
  • 1,809
  • 3
  • 21
  • 39
3

I checked the Node version in my local machine, which is v10.11.0.

Then when I checked my development machine, where the error occurred, it had Node version V.10.8.0.

Upgrading Node to v10.11.0 in my development machine fixed the issue.

Hope this helps.

Sofia Paixão
  • 309
  • 2
  • 16
davecar21
  • 2,606
  • 21
  • 33
3

One of the cases is the post-install process fails. Right after node-sass is installed, the post-install script will be executed. It requires Python and a C++ builder for that process. The log 'gyp: No Xcode or CLT version detected!' maybe because it couldn't find any C++ builder. So try installing Python and any C++ builder then put their directories in environment variables so that npm can find them. (I come from Windows)

Van Hung
  • 124
  • 1
  • 6
2

There is an issue with downloading npm dependencies due to network which you have. try to download the npm dependencies in open network . you won't get any issue. i am also faced this similar issue and resolved finally.

use below commands: npm install (it will download all depedencies) npm start to start the angular application

Ravi Maroju
  • 657
  • 6
  • 11
2

npm install node-sass will do the job in most of the cases, as it will add missing sass npm dependency module doesn't exist or it will overwrite previous crashed version.

For Mac Users use sudo in front of above commands.

On Windows machines npm rebuild node-sass --force may not work for some users because it's essentially saying, "please force npm to rebuild the sass node module for me". It will not work because that module doesn't exist.

Whenever you did npm install to the initial installation, the sass module did not get installed, which is why this problem occurs.

surendrapanday
  • 530
  • 3
  • 13
2

My problem was that a webfilter didn't allow me to download the node-sass package, when I executed the command

npm i

After the installation of the Windows Build Tools

npm i -g windows-build-tools

it build node-sass on it's own and now I can use it.

PS: I also installed Python 2.7.17 before, but I don't think that helped.

testing
  • 19,681
  • 50
  • 236
  • 417
2

Try sudo npm install node-sass@4.12.0 if your node version is 12.

M--
  • 25,431
  • 8
  • 61
  • 93
Sajid Javed
  • 452
  • 8
  • 14
2

I had the same error when installing dependencies in Angular. I've tried aforementioned techniques but none of them worked until I've deleted package-lock.json which was previously created when running Node v11.

Now I'm using Node v12 so this is how I got resolved.

I repeat if you have package-lock.json delete it, file and then install dependencies.

Muhammad Waqas Dilawar
  • 1,844
  • 1
  • 23
  • 34
2

you must install node-sass in dev section of package.json

npm install --unsafe-perm node-sass --save-dev  
hamid_reza hobab
  • 925
  • 9
  • 21
1

If you run

npm install node-sass

and it still doesn't work remember to change permission to folder

1

I have also been facing this error. None of the above methods work for me. Please follow this as it worked for me.

For Installing node-sass in Ubuntu 16 via npm :-

You can install with npm 5.2.0 Version

If you are using nvm :-

nvm install 8.2.1
nvm use 8.2.1
npm install node-sass

If you are using npm separately then upgrade or downgrade npm version to 5.2.0

npm install node-sass
Dale K
  • 25,246
  • 15
  • 42
  • 71
1

I ran into this error while I was using Microsoft Visual Studio Code's integrated git terminal. For some weird reason VS code was not allowing me to install 'node-sass'. Then I used 'Git Bash' (which was installed with git) and ran the following command: npm install node-sass It worked for me. I don't know why & how it worked. If anyone has any explanation please let me know.

snsakib
  • 1,062
  • 9
  • 14
1

You should try to check the log generated by npm install.

I have faced the same issues, and I found the error that python2 is not found in the path (environment variable).

After installing Python, everything worked fine.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Nadreak
  • 11
  • 2
1

I had a similar issue when I tried to run a project. First i uninstalled the current version

npm uninstall node-sass

Then i reinstalled to the latest version with

npm install node-sass
lp_nave
  • 244
  • 3
  • 17
1

Upgrading to latest version of nodeJS solved my problem

Omtechguy
  • 3,321
  • 7
  • 37
  • 71
1

npm install --save-dev --unsafe-perm node-sass

This will do magic, you can use it with sudo

yasir_mughal
  • 112
  • 10
1

Exactly same issue i was also facing and i tried all above answers but could not resolve, Below is the command which fixed my problem.

npm install sass-loader sass webpack --save-dev

https://www.npmjs.com/package/sass-loader

shrikant
  • 441
  • 5
  • 11
0

I've fixed this problem by installing v10.16.10 node version.

Dionis Oros
  • 664
  • 8
  • 12
0

I met same issue installing node-sass when I am on Node 12.9.0

Once switching to Node 10.19.0, the issue is gone.

Reference: https://github.com/sass/node-sass/issues/2632

Hongbo Miao
  • 45,290
  • 60
  • 174
  • 267
0

There seems to be an issue with the version "node-sass": "4.5.3", try updating to the latest version. Such as you could try adding ^ "node-sass": "^4.5.3" for the latest version

abdulwahid211
  • 722
  • 5
  • 4
0

Use this version for node version v 14

"node-sass": "^5.0.0"

Deen John
  • 3,522
  • 4
  • 29
  • 32
0

I had to uninstall then reinstall Xcode. That fixed the error for me.

-3

What fixed it for me was installing the latest version of node-sass, in this case 4.7.2.

bier hier
  • 20,970
  • 42
  • 97
  • 166
  • 7
    Install how? In the project or global? – lealceldeiro Apr 06 '18 at 13:29
  • @lealceldeiro: why would you install node-sass globally? if you have a project with scss files, you should install it in project level. for your how to install: all npm packages are installed by running npm install or using yarn. – Janatbek Orozaly May 26 '21 at 02:40
-3

just run this command in terminal, it will install latest version of node-sass

npm install node-sass

Taimoor Tahir
  • 430
  • 4
  • 6