23

I executed a update to angular 6. And during ng serve -o I receive error that sass-loader expect node-sass. After run ng serve -o I receive:

ERROR in ./src/sass/styles.scss (./node_modules/raw-loader!./node_modules/postcss-loader/lib??embedded!./node_modules/sass-loader/lib/loader.js??ref--14-3!./src/sass/styles.scss)
    Module build failed: Error: `sass-loader` requires `node-sass` >=4. Please install a compatible version.
    at Object.sassLoader (node_modules\sass-loader\lib\loader.js:31:19)
ERROR in ./src/app/app.component.scss
Module build failed: Error: `sass-loader` requires `node-sass` >=4. Please install a compatible version.
    at Object.sassLoader (node_modules\sass-loader\lib\loader.js:31:19)
ERROR in x.component.scss
Module build failed: Error: `sass-loader` requires `node-sass` >=4. Please install a compatible version.
    at Object.sassLoader (\node_modules\sass-loader\lib\loader.js:31:19)
ERROR in x.component.scss
Module build failed: Error: `sass-loader` requires `node-sass` >=4. Please install a compatible version.
    at Object.sassLoader (loader.js:31:19)
ERROR in .x.component.scss
Module build failed: Error: `sass-loader` requires `node-sass` >=4. Please install a compatible version.
    at Object.sassLoader (node_modules\sass-loader\lib\loader.js:31:19)

Obvisously I check everything (in my opinion) and I don't have idea what's going on.

Package.Json:

"devDependencies": {
"@angular-devkit/build-angular": "~0.6.0",
"@angular/cli": "6.0.0",
"@angular/compiler-cli": "6.0.0",
"@angular/language-service": "6.0.0",
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.106",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-html-detailed-reporter": "^1.1.21",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-phantomjs-launcher": "^1.0.4",
"karma-teamcity-reporter": "^1.1.0",
"phantomjs-prebuilt": "^2.1.16",
"protractor": "~5.1.2",
"node-sass": "^4.9.0",
"sass-loader": "^7.0.1",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "2.7.2"
}

dir -l node_modules says:

...
05/07/2018  08:53 AM    <DIR>          node-sass
...
05/07/2018  08:53 AM    <DIR>          sass-loader
...

I executed:

npm rebuild node-sass 

and secod approach: I removed local node-module together with %User%\AppData\Roaming\npm-cache. then I removed lock file and execuded npm

npm cache clear --force
npm install

But still no success.

What do I miss ?

Bartosz Kowalczyk
  • 1,479
  • 2
  • 18
  • 34
  • `sass-loader` is a dependency of angular so there is no need to specify it in the package.json. Try removing `node-sass` and `sass-loader` from the json, clear everything, install and build. – Leon May 07 '18 at 10:30
  • 1
    Having the same problem using `node 10.0.0` ... I now downgraded to `node 9.11.1` again and now it works ... not sure what the reason might be .... – Sebastian Hildebrandt May 07 '18 at 11:52
  • 6
    Had the same problem. I can see you've done a rebuild already, but try a rebuild of everything: `npm rebuild --force`. That fixed it for me. – DarkNeuron May 07 '18 at 16:10
  • @Sebastian Hildebrandt I am thinking to downgrade to node 9.11 from Node 10. After that do I have to install any other modules? After upgrading to Window 10 my application stopped working and am getting the same error (Module build failed: Error: `sass-loader` requires `node-sass` >=4. ) After installing this am getting the error to install Python 2 and set the PATH. I have Python 3.x installed. Now do I have to downgrade to Python 2? My setup: Angular CLI: 6.2.1 / Node: 10.0.0 / OS: win32 x64 – aswininayak Sep 10 '18 at 14:56

9 Answers9

38
npm rebuild --force

aslo helps

Adham Amiin
  • 809
  • 7
  • 5
  • 10
    A little explanation of what the command does would be appreciated – Jan B. May 24 '18 at 10:46
  • Doing this resolved my issue by updating the existing: `"node-sass": "^4.6.0"` to this: `"node-sass": "^4.12.0"`. Thanks for sharing! – Devner Feb 26 '20 at 06:37
11

I fixed it with

npm install node-sass

inside the project folder, and for the project, because installing it globally (with the -g option) didn't solve the issue.

halfer
  • 19,824
  • 17
  • 99
  • 186
10

I had same issue which I fixed using following steps:

  1. Delete package-lock.json file.
  2. Go to node_module folder and run rm -rf node_modules.
  3. Run npm install

The package-lock.json file will auto-update with the new dependencies version.

hope it helps.

candidJ
  • 4,289
  • 1
  • 22
  • 32
  • 2
    Did not work for me. But DarkNeuron's tip worked for me. – Razze May 08 '18 at 15:55
  • This problem occurred for me with an absolutely clean install on a CI server. –  May 20 '18 at 16:52
  • 3
    Might need 'npm rebuild node-sass' as step #4. Removing package-lock.json and node_modules results in pulling a new version of node-sass. However, this new version sometimes fails to build vendor.js when doing a plain 'npm install'. 'npm rebuild node-sass' builds vendor.js. No need to rebuild everything. – Maksym Jul 20 '18 at 15:39
  • I got "'rm' is not recognized as an internal or external command, operable program or batch file." – David Klempfner Apr 21 '22 at 02:49
  • I don't have a node-module folder, just node_modules with an "s" at the end. – David Klempfner Apr 21 '22 at 02:50
3

I fixed this issue using below steps:

  1. Open package.json
  2. Add which version you want to install of node-sass, for example "node-sass": "^4.12.0"
  3. Run the installation command in command line interface (CLI): npm install node-sass
  4. The issue will get resolved.
B--rian
  • 5,578
  • 10
  • 38
  • 89
2

Simply run this code...

npm install --save node-sass
Arun J
  • 687
  • 4
  • 14
  • 27
Karar Barcha
  • 406
  • 4
  • 11
1

To solve your issue run this command

npm install --unsafe-perm

Glenn Watson
  • 2,758
  • 1
  • 20
  • 30
0

Following steps solved this issue

  1. Delete node-saas folder in \Users\<user_id>\AppData\Roaming\npm-cache
  2. Delete node-saas folder in <application_folder>/node_modules
  3. Run npm install from <application_folder>
B--rian
  • 5,578
  • 10
  • 38
  • 89
Pradeep
  • 350
  • 1
  • 3
  • 13
0

It could probably be a version mismatch. To install the working node-sass version, you can use

npm uninstall node-sass
npm install node-sass@4.14.0

And you can choose your version number based on the following table, and the node version you have installed, which you can check by node --version

node-sass compatibility table

You can find full info here

This has solved my issue

Abraham
  • 12,140
  • 4
  • 56
  • 92
-1

You can follow these steps:

First of all Delete package-lock.json file and node_modules. and then Run npm install The package-lock.json file will auto-update with the new dependencies version.

Ryan M
  • 18,333
  • 31
  • 67
  • 74