77

I want to use the node-sass module in my node.js v0.12 application to benefit from the performance of libsass.
I executed npm i node-sass to install the module, no errors so far.

Now the mess starts:
If I just open the REPL in a terminal to try out node-sass then everything works fine but if I include it in my project files and run node myfile.js then I get the following error message:

Error: `libsass` bindings not found. Try reinstalling `node-sass`?

The module's description at npmjs.com states that there might be a problem with resolving #!/usr/bin/env node under Ubuntu and how to fix this but that is not the case on my machine.
I could not find anything useful so I hope that you might help me.

I'm using node v0.12.2 under Ubuntu 14.10.

P.S.: I already tried to reinstall node-sass but without success. Nothing changes.

TorbenJ
  • 4,462
  • 11
  • 47
  • 84
  • If Philipp's answer solved your issues, please accept. It fixed my issue. – Jazzy Jul 30 '15 at 19:59
  • I ran into this within my Ionic project after I updated to the lated NodeJS release -- the out put instructs to run a `npm rebuild node-sass`, which got rid of the error for me/my environment. – Cody May 15 '16 at 22:29

13 Answers13

272

If you're using node 4.x or later then you need to reinstall gulp-sass with:

npm uninstall --save-dev gulp-sass
npm install --save-dev gulp-sass@2
Wilson Silva
  • 10,046
  • 6
  • 26
  • 31
  • 2
    Thank you! I always forget how to solve this issue, and by far this was the simplest and quickest solution. – natdico Oct 16 '15 at 15:45
  • 3
    This fixed my issue! Was a result of updating node significantly. – ClickerMonkey Nov 17 '15 at 21:24
  • I didn't do like this but just changed the version number in package.json file manually to `2.1.0` from `1.x.x`. – Mr_Green Nov 27 '15 at 08:07
  • 4
    This finally did it for me, unlike pretty much every other reply to this question. +1 – João Feb 03 '16 at 10:06
  • 2
    Thank you Thank you Thank you! This little issue killed a demo once and I was afraid to upgrade and reverted back to 0.12.7, today I tried again, had the issue occur and this fixed it! – Giancarlo Gomez Feb 04 '16 at 17:03
  • 2
    this fixed it for me too...after weeks of trying other solutions and not having a test suite on my project. Thanks – Obi Jul 08 '16 at 05:17
  • 1
    thank you!! banging my head on this one for an hour now – MorningDew Jan 02 '17 at 23:05
  • 1
    This also worked exactly as written but for 'grunt-sass' instead of 'gulp-sass' if using grunt. (I have no idea how it worked... but it did) – voodooGQ Mar 13 '17 at 14:00
  • 1
    Yeah this fixed it thanks it was driving me nuts.. Also manually compiled libsass sassc but i dont think i need to doing this – JREAM Jul 24 '17 at 01:06
  • this is fixing it for node 0.12.0. – funky-nd Jul 16 '19 at 05:52
119

You’ve probably tried to reinstall node-sass while using

npm install node-sass

or

npm uninstall node-sass
npm install node-sass

But node-sass is a C version of Sass. You have to use npm rebuild:

npm rebuild node-sass
BryanH
  • 5,826
  • 3
  • 34
  • 47
Philipp Andreychev
  • 1,638
  • 2
  • 14
  • 14
  • 8
    When I try the rebuild command I get the error 'Error: Can't find Python executable "python"... Not sure mine is a C version of Sass – Edd Oct 01 '15 at 09:12
  • 1
    @Sebastian Native Abstractions for Node (nan) "change dramatically from one release to the next" and often need to be recompiled for each release. `node-sass` is entirely about binding `node` to `lib-sass`, a C program. links: [node addons](https://nodejs.org/api/addons.html#addons_native_abstractions_for_node_js), [a celebrated comment](https://github.com/sass/node-sass/issues/1527#issuecomment-217070514), [libsass](http://sass-lang.com/libsass) – Matthew Sep 15 '17 at 14:11
20

I fixed this issue by deleting the existing /node_modules folder and running npm update

Dallas Clark
  • 4,064
  • 3
  • 30
  • 36
  • 1
    tried this actually but in this case the /node_modules was under SVN control... deleting the directory threw the SVN tree out of sync. It's somewhat of a good option otherwise! – JsusSalv Jul 24 '15 at 07:08
  • This happens to me from time to time as well, and deleting `node_modules` and re-running `npm install` works for me as well. – Geo242 Sep 30 '15 at 00:11
  • 8
    Source control is a bad place to store dependencies for this reason! It requires complete lockstep of all your environments. `package.json` is designed to describe your dependencies, and you should use something else to install your dependencies on your boxes. (having a script that calls npm install, or a docker container, or or or) – AnilRedshift Oct 11 '15 at 01:07
  • Maybe he wanted a complete lockstep of all his environments? -- Predictable and Reproducible Builds != Bad idea. – BrainSlugs83 Nov 12 '15 at 22:30
  • 2
    Thats is what package.json is for. You don't want to store all the node_modules non-sense in source control. – Andrei Drynov Nov 13 '15 at 17:18
  • I did similar thing. but before that I manually changed the gulp-sass version to `2.1.0.` which worked for me. Thanks. – Mr_Green Nov 27 '15 at 08:06
  • @AFD While I agree that storing `node_modules` in source control is not ideal, `package.json` on its own does not freeze the versions. You can easily specify a specific version of a dependency within your `package.json`, but you have no control over how versions are declared within that dependency's `package.json`. – vegemite4me Oct 31 '18 at 17:24
8

This is the only solution that worked for me,

sudo npm install -g n
sudo n 0.12.7
npm install node-sass@2
sudo npm -g install node-gyp@3
npm rebuild node-sass
VisioN
  • 143,310
  • 32
  • 282
  • 281
Stranger
  • 10,332
  • 18
  • 78
  • 115
7

This workaround (http://forum.ionicframework.com/t/error-running-gulp-sass/32311/20) worked form me.

Starting with this setup:

Cordova CLI: 5.3.3 Gulp version: CLI version 3.9.0 Gulp local: Local version 3.9.0 Ionic Version: 1.1.0 Ionic CLI Version: 1.6.5 Ionic App Lib Version: 0.3.9 ios-deploy version: Not installed ios-sim version: 5.0.1 OS: Mac OS X Yosemite Node Version: v4.1.1 Xcode version: Xcode 6.4 Build version 6E35b

I've found a solution to avoid to use 'sudo' command. We need before to fix npm permissions following this: https://docs.npmjs.com/getting-started/fixing-npm-permissions and fixing permissions for Node here: http://mawaha.com/permission-fix-node-js/ After this we can check and reinstall software without 'sudo' for npm, n or ionic.

I followed this step:

npm install -g n
rm -R node_modules/ 
npm install node-sass@3.3.3 
npm -g install node-gyp@3
npm uninstall gulp-sass
npm install gulp-sass@2 
npm rebuild node-sass 
ionic setup sass 

Why node-sass@3.3.3? Because it works with latest ionic version: https://github.com/driftyco/ionic/pull/4449

Francesco
  • 1,128
  • 12
  • 22
5

Combining the two answers above worked for me, plus additions:

sudo npm uninstall --save gulp-sass
npm install --save gulp-sass@2
npm update
npm rebuild node-sass
Jadeye
  • 3,551
  • 4
  • 47
  • 63
3

I have solved this to create the right directory with the specified binding.node file. You can download the bindings from github

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

Look in the error message the path where it tries to find the binding. In my case:

C:\Users\Martijn\Documents\node_modules\gulp-sass\node_modules\node-sass\vendor\win32-x64-46

So I create this map win32-x64-46 and copy the binding from github in.

MartijnBrands
  • 91
  • 1
  • 6
2

My solution was to downgrade to v0.10.25 (try sudo n 0.10.25 if you use n)

nathanhleung
  • 506
  • 6
  • 14
1

For me, this issue was caused in my build system (Travis CI) by doing something kind of dumb in my .travis.yml file. In effect, I was calling npm install before nvm use 0.12, and this was causing node-sass to be built for 0.10 instead of 0.12. My solution was simply moving nvm use out of the .travis.yml file’s before_script section to before the npm install command, which was in the before_install section.

Alan H.
  • 16,219
  • 17
  • 80
  • 113
1

This was a Node version issue for me, try using nvm to backtrack your version to something like: 0.10.32. This worked for me. I was running 4.2.2

Kevin Alwell
  • 131
  • 10
0

I solved this problem by updating my gcc from 4.4.x to 4.7.x

Community
  • 1
  • 1
worldask
  • 1,837
  • 3
  • 22
  • 37
0

No need for sudo or re-installations. This has always worked for me:

nvm use 0.12.2
alexfigtree
  • 1,516
  • 14
  • 16
0

This is the steps I undertook to fix my issue.

  1. I updated my node manually to the latest version

  2. Reinstalled node-sass

npm install node-sass

3.npm audit fix to fix certain vulnerabilities.

`npm audit fix`

5.npm install node-sass

 `npm install node-sass`

worked and compiled properly thereafter. I apologize if anything related to my answer isn't right. I'm just a beginner. Hope it works for you