0
0

Using gulp-sass/node-sass on iojs v1.6

C.C. 发表于 2015年03月27日 12:34 | Hits: 2824

在iojs下如果遇到这样的错误:

/Users/fanweixiao/_wrk/test/node_modules/gulp-sass/node_modules/node-sass/lib/index.js:22
    throw new Error('`libsass` bindings not found. Try reinstalling `node-sass
          ^
Error: `libsass` bindings not found. Try reinstalling `node-sass`?  
    at getBinding (/Users/fanweixiao/_wrk/test/node_modules/gulp-sass/node_modules/node-sass/lib/index.js:22:11)
    at Object.<anonymous> (/Users/fanweixiao/_wrk/test/node_modules/gulp-sass/node_modules/node-sass/lib/index.js:188:23)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:428:10)
    at Module.load (module.js:335:32)
    at Function.Module._load (module.js:290:12)
    at Module.require (module.js:345:17)
    at require (module.js:364:17)
    at Object.<anonymous> (/Users/fanweixiao/_wrk/test/node_modules/gulp-sass/index.js:3:17)
    at Module._compile (module.js:410:26)

1. Reinstallnode-sasswhich insidegulp-sass

cd node_modules/gulp-sass/  
npm uninstall node-sass  
npm install node-sass --verbose  

将会看到:

npm info install node-sass@2.0.1

> node-sass@2.0.1 install /Users/fanweixiao/_wrk/test/node_modules/gulp-sass/node_modules/node-sass
> node scripts/install.js

Can not download file from https://raw.githubusercontent.com/sass/node-sass-binaries/v2.0.1/darwin-x64-iojs-1.6/binding.node  
npm verb unsafe-perm in lifecycle true  
npm info postinstall node-sass@2.0.1

> node-sass@2.0.1 postinstall /Users/fanweixiao/_wrk/test/node_modules/gulp-sass/node_modules/node-sass
> node scripts/build.js

module.js:318  
    throw err;
          ^
Error: Cannot find module '/Users/fanweixiao/_wrk/test/node_modules/gulp-sass/node_modules/node-sass/node_modules/pangyp/bin/node-gyp'  
    at Function.Module._resolveFilename (module.js:316:15)
    at Function.Module._load (module.js:258:25)
    at Function.Module.runMain (module.js:451:10)
    at startup (node.js:123:18)
    at node.js:868:3
Build failed  

2. Installpangypinsidenode-sass

cd node_modules/node-sass/  
npm install pangyp --verbose  

3. Rerun install script ofnode-sass

# 在node_modules/gulp-sass/node_modules/node-sass/下运行
npm run install  

调试方法

查看`nodemodules/gulp-sass/nodemodules/node-sass/lib/index.js':

function getBinding() {  
  var candidates = [
    path.join(__dirname, '..', 'build', 'Debug', 'binding.node'),
    path.join(__dirname, '..', 'build', 'Release', 'binding.node'),
    path.join(__dirname, '..', 'vendor', process.sassBinaryName, 'binding.node')
  ];

  /************ Debug candidates ***********/
  console.log(candidates);

  var candidate = candidates.filter(fs.existsSync).shift();

  if (!candidate) {
    throw new Error('`libsass` bindings not found. Try reinstalling `node-sass`?');
  }

  return candidate;
}

添加了:

/************ Debug candidates ***********/
console.log(candidates);  

再次运行gulp sass:

[ '/Users/fanweixiao/_wrk/test/node_modules/gulp-sass/node_modules/node-sass/build/Debug/binding.node',
  '/Users/fanweixiao/_wrk/test/node_modules/gulp-sass/node_modules/node-sass/build/Release/binding.node',
  '/Users/fanweixiao/_wrk/test/node_modules/gulp-sass/node_modules/node-sass/vendor/darwin-x64-iojs-1.6/binding.node' ]
/Users/fanweixiao/_wrk/test/node_modules/gulp-sass/node_modules/node-sass/lib/index.js:23
    throw new Error('`libsass` bindings not found. Try reinstalling `node-sass
          ^
Error: `libsass` bindings not found. Try reinstalling `node-sass`?  
    at getBinding (/Users/fanweixiao/_wrk/test/node_modules/gulp-sass/node_modules/node-sass/lib/index.js:23:11)

看到输出的内容是:

[ '/Users/fanweixiao/_wrk/test/node_modules/gulp-sass/node_modules/node-sass/build/Debug/binding.node',
  '/Users/fanweixiao/_wrk/test/node_modules/gulp-sass/node_modules/node-sass/build/Release/binding.node',
  '/Users/fanweixiao/_wrk/test/node_modules/gulp-sass/node_modules/node-sass/vendor/darwin-x64-iojs-1.6/binding.node' ]

那我们直接去下载node-sass的binary去(node-sass-binaries):

mkdir -p node_modules/gulp-sass/node_modules/node-sass/vendor/darwin-x64-iojs-1.6

cd node_modules/gulp-sass/node_modules/node-sass/vendor/darwin-x64-iojs-1.6

wget https://github.com/sass/node-sass-binaries/blob/master/darwin-x64-43_binding.node -O binding.node  

如果直接用node-sass的3.0.0-beta.2这种方法最简单了

原文链接: http://onlyvc.us/using-gulp-sassnode-sass-on-iojs-v1-6/

0     0

我要给这篇文章打分:

可以不填写评论, 而只是打分. 如果发表评论, 你可以给的分值是-5到+5, 否则, 你只能评-1, +1两种分数. 你的评论可能需要审核.

评价列表(0)