Twitter-Node 无法构建 Node.js (npm install twitter-node)

标签 twitter node.js

我正在尝试安装“Twitter-Node”(npm install twitter-node)。 Node JS .3.2-pre 版本。

当我尝试安装时,我收到以下错误。对我可能做错了什么有什么想法吗?对我来说,安装似乎非常简单。我也成功安装了 socket-io...

m ERR! Error: twitter-node@0.0.2 preinstall: `./build.sh`
npm ERR! `sh` failed with 1
npm ERR!     at ChildProcess.<anonymous> (/usr/local/lib/node/.npm/npm/0.2.12-    1/package/lib/utils/exec.js:25:18)
npm ERR!     at ChildProcess.emit (events.js:34:17)
npm ERR!     at ChildProcess.onexit (child_process.js:164:12)
npm ERR! 
npm ERR! Failed at the twitter-node@0.0.2 preinstall script.
npm ERR! This is most likely a problem with the twitter-node package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     ./build.sh

alt text

最佳答案

简单的解决方案

从这里获取它:
https://github.com/patmcnally/twitter-node

npm 上的模块很旧(上次更新时间为 8 月 31 日),并且因设计而损坏,它编译自己的 Base64 编码器,而不是使用 Node 的内置功能。<​​/p>

安装:

  1. 下载存档并解压
  2. cd 进入该文件夹并运行 npm install 。
  3. 祝你有美好的一天:)

旧答案

安装运行 gcc 来编译依赖于 Node Buffer 类(C++ 实现)的 base64 模块,因为 3.x 中对此进行了相当多的更改,所以它爆炸了!

Waf: Entering directory `/home/ivo/.local/lib/node/.npm/twitter-node/0.0.2/package/vendor/node-base64/build'
[1/2] cxx: base64.cc -> build/default/base64_1.o
../base64.cc: In function ‘v8::Handle<v8::Value> base64_encode_binding(const v8::Arguments&)’:
../base64.cc:178: error: ‘class node::Buffer’ has no member named ‘data’
../base64.cc:178: error: ‘class node::Buffer’ has no member named ‘length’
../base64.cc: In function ‘v8::Handle<v8::Value> base64_decode_binding(const v8::Arguments&)’:
../base64.cc:199: error: ‘class node::Buffer’ has no member named ‘data’
../base64.cc:199: error: ‘class node::Buffer’ has no member named ‘length’
Waf: Leaving directory `/home/ivo/.local/lib/node/.npm/twitter-node/0.0.2/package/vendor/node-base64/build'
Build failed:  -> task failed (err #1): 
    {task: cxx base64.cc -> base64_1.o}

This commit删除了这两个成员并用静态内联方法替换了它们。

.npm/twitter-node/0.0.2/package/vendor/node-base64/base64.cc中,您需要替换行177/178198/199,如下所示:

Buffer *buffer = ObjectWrap::Unwrap<Buffer>(args[0]->ToObject());
char *str = base64_encode((unsigned char*)buffer->data(), buffer->length(),&len);

这样:

Local<Object> buffer = args[0]->ToObject();
char *str = base64_encode((unsigned char*)Buffer::Data(buffer), Buffer::Length(buffer),&len);  

然后运行npm重建twitter-node就大功告成了!不要使用安装,因为它将重新下载并覆盖更改。

PS:我必须使用 require('twitter-node@0.0.2') 来导入它,因为 npm 没有在 .local/lib/node 中创建符号链接(symbolic link),但您可以轻松地自行修复它。

更新

我确实看了一下这个模块,这太搞笑了,他们编译了一个 80kb 的库,如果更改为 Node.js 只是为了一次使用 Base64 编码,则很容易失败。

// Returns a Basic Auth header fit for HTTP.
var basicAuth = function basicAuth(user, pass) {
    return "Basic " + b64.encode(user + ":" + pass);
};

这做了完全相同的事情,并且不会因 Node.js 的其他所有更改而爆炸:

new Buffer(user + ':' + pass).toString('base64')

关于Twitter-Node 无法构建 Node.js (npm install twitter-node),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4407531/

相关文章:

node.js - 使用 Node 驱动程序在主机之间克隆 Mongodb 中的数据库

node.js - 转换发布带有显示次数的 MeteorJS

node.js - Mocha Chai 测试 protected 路线

twitter - 如何使用 c# 为 Twitter API 1.1 生成 OAuth 签名?

python - 使用基于字符串数组中元素的集合名称在 pymongo 中创建 MongoDB 集合

iphone - Twitter:身份验证已更改?应用程序突然在身份验证窗口(钛)上崩溃

python - 使用Bash工具解析JSON

javascript - 有没有办法在 twitter 嵌入式小部件中更新推文列表时通知?

node.js - Socket.io 需要很长时间才能连接

node.js - 使用sequelize的sql中双冒号的用法是什么?