在 nodejs 中使用 node-sass 时找不到 libsass 绑定
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29461831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
libsass bindings not found when using node-sass in nodejs
提问by TorbenJ
I want to use the node-sassmodule in my node.js v0.12application to benefit from the performance of libsass.
I executed npm i node-sassto install the module, no errors so far.
我想node-sass在我的node.js v0.12应用程序中使用该模块以从libsass.
我执行npm i node-sass安装模块,到目前为止没有错误。
Now the mess starts:
If I just open the REPLin a terminal to try out node-sassthen everything works fine but if I include it in my project files and run node myfile.jsthen I get the following error message:
现在混乱开始了:
如果我只是REPL在终端中打开来尝试,node-sass那么一切正常,但是如果我将它包含在我的项目文件中并运行,node myfile.js那么我会收到以下错误消息:
Error: `libsass` bindings not found. Try reinstalling `node-sass`?
The module's description at npmjs.comstates that there might be a problem with resolving #!/usr/bin/env nodeunder 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.
npmjs.com 上的模块描述指出,#!/usr/bin/env node在 Ubuntu 下解析可能存在问题以及如何解决此问题,但在我的机器上并非如此。
我找不到任何有用的东西,所以我希望你能帮助我。
I'm using node v0.12.2 under Ubuntu 14.10.
我在 Ubuntu 14.10 下使用 node v0.12.2。
P.S.: I already tried to reinstall node-sass but without success. Nothing changes.
PS:我已经尝试重新安装 node-sass 但没有成功。没有什么改变。
回答by Wilson Silva
If you're using node 4.x or later then you need to reinstall gulp-sass with:
如果您使用的是 node 4.x 或更高版本,则需要使用以下命令重新安装 gulp-sass:
npm uninstall --save-dev gulp-sass
npm install --save-dev gulp-sass@2
回答by Philipp Andreychev
You've probably tried to reinstall node-sass while using
您可能已经尝试在使用时重新安装 node-sass
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:
但是 node-sass 是 Sass 的 C 版本。你必须使用npm rebuild:
npm rebuild node-sass
回答by Dallas Clark
I fixed this issue by deleting the existing /node_modulesfolder and running npm update
我通过删除现有/node_modules文件夹并运行来解决此问题npm update
回答by Stranger
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
回答by Francesco
This workaround (http://forum.ionicframework.com/t/error-running-gulp-sass/32311/20) worked form me.
这个解决方法(http://forum.ionicframework.com/t/error-running-gulp-sass/32311/20)对我有用。
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
Cordova CLI:5.3.3 Gulp 版本:CLI 版本 3.9.0 Gulp local:本地版本 3.9.0 Ionic 版本:1.1.0 Ionic CLI 版本:1.6.5 Ionic App Lib 版本:0.3.9 ios-deploy 版本:未安装ios-sim 版本:5.0.1 操作系统:Mac OS X Yosemite Node 版本:v4.1.1 Xcode 版本: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-permissionsand 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.
我找到了避免使用“sudo”命令的解决方案。我们需要在此之前修复 npm 权限:https: //docs.npmjs.com/getting-started/fixing-npm-permissions并在此处修复节点的权限:http: //mawaha.com/permission-fix-node- js/在此之后,我们可以检查并重新安装软件,而无需为 npm、n 或 ionic 使用“sudo”。
I followed this step:
我遵循了这一步:
npm install -g n
rm -R node_modules/
npm install [email protected]
npm -g install node-gyp@3
npm uninstall gulp-sass
npm install gulp-sass@2
npm rebuild node-sass
ionic setup sass
Why [email protected]? Because it works with latest ionic version: https://github.com/driftyco/ionic/pull/4449
为什么是 [email protected]?因为它适用于最新的离子版本:https: //github.com/driftyco/ionic/pull/4449
回答by Jadeye
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
回答by MartijnBrands
I have solved this to create the right directory with the specified binding.node file. You can download the bindings from github
我已经解决了这个问题,用指定的 binding.node 文件创建了正确的目录。您可以从 github 下载绑定
https://github.com/sass/node-sass-binaries
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
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.
所以我创建了这个地图 win32-x64-46 并将绑定从 github 复制进来。
回答by nathanhleung
My solution was to downgrade to v0.10.25(try sudo n 0.10.25if you use n)
我的解决方案是降级到v0.10.25(sudo n 0.10.25如果你使用n)
回答by Alan H.
For me, this issue was caused in my build system (Travis CI) by doing something kind of dumb in my .travis.ymlfile. In effect, I was calling npm installbeforenvm use 0.12, and this was causing node-sassto be built for 0.10instead of 0.12. My solution was simply moving nvm useout of the .travis.ymlfile's before_scriptsection to before the npm installcommand, which was in the before_installsection.
对我来说,这个问题是在我的构建系统 (Travis CI) 中通过在我的.travis.yml文件中做一些愚蠢的事情引起的。实际上,我npm install之前在调用nvm use 0.12,这导致node-sass构建为0.10而不是0.12. 我的解决方案是简单地移动nvm use了的.travis.yml文件的before_script中前部分npm install的命令,这是在before_install一节。
回答by Kevin Alwell
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
这对我来说是一个 Node 版本问题,尝试使用 nvm 将您的版本回溯到类似:0.10.32。这对我有用。我正在运行 4.2.2

