4

我在 Heroku 上编译 socket.io 应用程序时遇到了一些问题。

那就是 app.js 文件

var app = require('express').createServer()
   , io = require('socket.io').listen(app.listen(process.env.PORT || 5000));

app.get('/', function (req, res) {
    res.sendfile(__dirname + '/index.html');
});

var users = [];

  io.configure(function () { 
  io.set("transports", ["xhr-polling"]); 
  io.set("polling duration", 10); 
});

io.sockets.on('connection', function (socket) {

  socket.on('message',function(data,time,username){


    socket.broadcast.emit('message',data,time,username);

    socket.emit('message',data,time,username,true);
  });

  socket.on('connected',function(username){

    socket.nick = username;

    users.push(username);

    io.sockets.emit('user_connected',users);
  });

  socket.on('disconnect',function(){

    users.splice(users.indexOf(socket.nick), 1);

    socket.broadcast.emit('updated_user_list',users);
  });

});

包.json

{
  "name": "application-name",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node app"
  },
  "engines": {
    "node": "0.8.x",
    "npm":  "1.1.x"
  },
  "dependencies": {
    "express": "3.0.0rc1",
    "jade": "*",
    "socket.io": "~0.9.8"
  }
}

这就是将它推到heroku时的错误

[gaggina:~/Desktop/socket2]→git push heroku master
Counting objects: 1016, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (892/892), done.
Writing objects: 100% (1016/1016), 3.90 MiB | 104 KiB/s, done.
Total 1016 (delta 74), reused 0 (delta 0)

-----> Heroku receiving push
-----> Node.js app detected
-----> Resolving engine versions
       Using Node.js version: 0.8.3
       Using npm version: 1.1.41
-----> Fetching Node.js binaries
-----> Vendoring node into slug
-----> Installing dependencies with npm
       npm WARN package.json application-name@0.0.1 No README.md file found!
       npm WARN package.json jade@0.26.3 No README.md file found!
       npm WARN package.json application-name@0.0.1 No README.md file found!
       npm WARN package.json jade@0.26.3 No README.md file found!
       npm WARN package.json connect@2.4.1 No README.md file found!
       npm WARN package.json methods@0.0.1 No README.md file found!
       npm WARN package.json hiredis@0.1.14 No README.md file found!

       > ws@0.4.21 install /tmp/build_3gzqoe2cjr234/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws
       > node install.js

       [ws v0.4.21] Attempting to compile blazing fast native extensions.
       [ws v0.4.21] Native extension compilation successful!

       > hiredis@0.1.14 preinstall /tmp/build_3gzqoe2cjr234/node_modules/socket.io/node_modules/redis/node_modules/hiredis
       > make || gmake

       cd deps/hiredis && make static
       make[1]: Entering directory `/tmp/build_3gzqoe2cjr234/node_modules/socket.io/node_modules/redis/node_modules/hiredis/deps/hiredis'
       make[1]: Nothing to be done for `static'.
       make[1]: Leaving directory `/tmp/build_3gzqoe2cjr234/node_modules/socket.io/node_modules/redis/node_modules/hiredis/deps/hiredis'
       node-waf configure build
       Setting srcdir to                        : /tmp/build_3gzqoe2cjr234/node_modules/socket.io/node_modules/redis/node_modules/hiredis 
       Setting blddir to                        : /tmp/build_3gzqoe2cjr234/node_modules/socket.io/node_modules/redis/node_modules/hiredis/build 
       Checking for program g++ or c++          : /usr/bin/g++ 
       Checking for program cpp                 : /usr/bin/cpp 
       Checking for program ar                  : /usr/bin/ar 
       Checking for program ranlib              : /usr/bin/ranlib 
       Checking for g++                         : ok  
       Checking for node path                   : not found 
       Checking for node prefix                 : ok /tmp/node-node-de4o 
       'configure' finished successfully (1.834s)
       Waf: Entering directory `/Users/gaggina/Desktop/socket2/node_modules/socket.io/node_modules/redis/node_modules/hiredis/build'
       Waf: Leaving directory `/Users/gaggina/Desktop/socket2/node_modules/socket.io/node_modules/redis/node_modules/hiredis/build'
       Traceback (most recent call last):
         File "/tmp/node-node-de4o/bin/node-waf", line 16, in <module>
           Scripting.prepare(t, os.getcwd(), VERSION, wafdir)
         File "/tmp/node-node-de4o/bin/../lib/node/wafadmin/Scripting.py", line 145, in prepare
           prepare_impl(t, cwd, ver, wafdir)
         File "/tmp/node-node-de4o/bin/../lib/node/wafadmin/Scripting.py", line 135, in prepare_impl
           main()
         File "/tmp/node-node-de4o/bin/../lib/node/wafadmin/Scripting.py", line 188, in main
           fun(ctx)
         File "/tmp/node-node-de4o/bin/../lib/node/wafadmin/Scripting.py", line 386, in build
           return build_impl(bld)
         File "/tmp/node-node-de4o/bin/../lib/node/wafadmin/Scripting.py", line 405, in build_impl
           bld.compile()
         File "/tmp/node-node-de4o/bin/../lib/node/wafadmin/Build.py", line 268, in compile
           os.chdir(self.bldnode.abspath())
       OSError: [Errno 2] No such file or directory: '/Users/gaggina/Desktop/socket2/node_modules/socket.io/node_modules/redis/node_modules/hiredis/build'
       make: *** [all] Error 1
       sh: gmake: not found
       npm ERR! hiredis@0.1.14 preinstall: `make || gmake`
       npm ERR! `sh "-c" "make || gmake"` failed with 127
       npm ERR! 
       npm ERR! Failed at the hiredis@0.1.14 preinstall script.
       npm ERR! This is most likely a problem with the hiredis package,
       npm ERR! not with npm itself.
       npm ERR! Tell the author that this fails on your system:
       npm ERR!     make || gmake
       npm ERR! You can get their info via:
       npm ERR!     npm owner ls hiredis
       npm ERR! There is likely additional logging output above.

       npm ERR! System Linux 2.6.32-343-ec2
       npm ERR! command "/tmp/node-node-de4o/bin/node" "/tmp/node-npm-Xp2N/cli.js" "rebuild"
       npm ERR! cwd /tmp/build_3gzqoe2cjr234
       npm ERR! node -v v0.8.3
       npm ERR! npm -v 1.1.41
       npm ERR! code ELIFECYCLE
       npm ERR! stack Error: hiredis@0.1.14 preinstall: `make || gmake`
       npm ERR! stack `sh "-c" "make || gmake"` failed with 127
       npm ERR! stack     at ChildProcess.<anonymous> (/tmp/node-npm-Xp2N/lib/utils/exec.js:56:20)
       npm ERR! stack     at ChildProcess.EventEmitter.emit (events.js:91:17)
       npm ERR! stack     at Process._handle.onexit (child_process.js:674:10)
       npm ERR! 
       npm ERR! Additional logging details can be found in:
       npm ERR!     /tmp/build_3gzqoe2cjr234/npm-debug.log
       npm ERR! not ok code 0
 !     Failed to rebuild dependencies with npm
 !     Heroku push rejected, failed to compile Node.js app

To git@heroku.com:boiling-beyond-2052.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:boiling-beyond-2052.git'
[gaggina:~/Desktop/socket2]→cat /tmp/build_3gzqoe2cjr234/npm-debug.log
cat: /tmp/build_3gzqoe2cjr234/npm-debug.log: No such file or directory
4

6 回答 6

2

Heroku 未能构建hiredis。原因是hiredis(node.js 模块)依赖于hiredis(C 库),它需要GNU make,这在你的slug 上不可用。

问题是,为什么 NPM 尝试构建不在您的依赖项中的hiredis?

您应该检查hiredis 是否出现在您的项目中的任何位置(grep -R hiredis .)。另一种可能性是 Heroku 正在尝试为所有 node.js 应用程序提供 redis ?

我会检查 Heroku 的支持。

于 2012-08-03T13:51:56.480 回答
0

WAAAAAAAIT 一秒钟。

在我运行之后我注意到在grep -R hiredis .目录下./node_modules/socket.io/node_modules出现了文件夹redis。显然,socket.io现在是redis内置的,这与 Heroku 混淆了。

尝试redissocket.io's文件夹中删除文件node_modules夹。我通过完全删除 socket.io 解决了这个问题。

于 2013-03-11T22:45:13.490 回答
0

我在搞乱heroku时遇到了同样的问题。所有的路径似乎都在那里。运行 Ubuntu 12.04,我什至为 gmake 创建了一个符号链接。没有什么能解决它。我最终尝试了这个

"dependencies": {
  "express": "3.0.0rc2",
  "ejs": "*",
  "stylus": "*",
  "mongojs": "0.4.3"
},
"bundledDependencies": {
  "socket.io": "*"
},

代替

"dependencies": {
  "express": "3.0.0rc2",
  "ejs": "*",
  "stylus": "*",
  "mongojs": "0.4.3",
  "socket.io": "*"
},

这似乎解决了它并使heroku高兴。如果您找到合适的解决方案,请告诉我。

于 2012-08-14T14:14:35.863 回答
0

当您在npm install本地运行时,hiredis 会创建一些具有特定于您机器的路径的文件。当您将这些缓存的依赖项推送到 Heroku 时,构建会失败。

Waf: Entering directory `/Users/gaggina/Desktop/socket2/node_modules/socket.io/node_modules/redis/node_modules/hiredis/build'

你可以通过node_modules/hiredis从源代码管理中删除目录,让 Heroku 重新编译它来解决这个问题:

git rm -rf node_modules/hiredis
rm -rf node_modules/hiredis
echo "node_modules/hiredis" >> .gitignore
于 2013-03-15T07:44:25.070 回答
0

我已经在将 nodejs 部署到 heroku时发布了一个类似问题的答案,这似乎已经解决了这个问题。

基本上尝试使用 socket.io 0.9.6 而不是 0.9.8。

于 2012-08-14T14:48:58.127 回答
0

我做了一些谷歌搜索,但找不到解决方案,但我尝试如下更改我的代码,它开始工作......

var express = require('express'),
    app = express(), 
    server = require('http').createServer(app),
    io = require('socket.io').listen(server),

var port = process.env.PORT || 5000; // Use the port that Heroku provides or default to 5000

server.listen(port, function() {
});

io.configure(function () {
    io.set("transports", ["xhr-polling"]);
    io.set("polling duration", 10);
    io.set("log level", 1);
});

让我知道你是否同样​​的问题,但仍然没有成功..

于 2013-08-23T06:51:12.947 回答