gaggina
gaggina

Reputation: 5425

socket.io + node.js on heroku

I'm having some issues in compiling a socket.io app on heroku.

Thats the app.js file

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);
  });

});

package.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"
  }
}

And that's the error when pushing it to 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 [email protected] No README.md file found!
       npm WARN package.json [email protected] No README.md file found!
       npm WARN package.json [email protected] No README.md file found!
       npm WARN package.json [email protected] No README.md file found!
       npm WARN package.json [email protected] No README.md file found!
       npm WARN package.json [email protected] No README.md file found!
       npm WARN package.json [email protected] No README.md file found!

       > [email protected] 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!

       > [email protected] 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! [email protected] preinstall: `make || gmake`
       npm ERR! `sh "-c" "make || gmake"` failed with 127
       npm ERR! 
       npm ERR! Failed at the [email protected] 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: [email protected] 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 [email protected]:boiling-beyond-2052.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to '[email protected]: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

Upvotes: 4

Views: 3984

Answers (6)

Dhrumil Shah
Dhrumil Shah

Reputation: 2176

I did some googling but cant find the solution, But i tried to change my code as below and it started to work...

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);
});

let me know if you same issue and still not getting success..

Upvotes: 0

Zeke
Zeke

Reputation: 1448

When you run npm install locally, hiredis creates some files with paths that are specific to your machine. When you push these cached dependencies to Heroku, the build fails.

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

You can get around this problem by removing the node_modules/hiredis directory from source control, letting Heroku compile it anew:

git rm -rf node_modules/hiredis
rm -rf node_modules/hiredis
echo "node_modules/hiredis" >> .gitignore

Upvotes: 0

Willy VVu
Willy VVu

Reputation: 16

WAAAAAAAIT A SECOND.

I noticed after I ran grep -R hiredis . that under the directory ./node_modules/socket.io/node_modules there appears the folder redis. Apparently, socket.io is now shipping with redis built in, which messes with Heroku.

Try fooling around with removing the redis folder from socket.io's node_modules folder. I solved the issue by removing socket.io altogether.

Upvotes: 0

Gautham Badhrinathan
Gautham Badhrinathan

Reputation: 2437

I've posted an answer to a similar question at deploy nodejs to heroku and that seems to have solved the problem.

Basically try using socket.io 0.9.6 instead of 0.9.8.

Upvotes: 0

narak
narak

Reputation: 451

I was running into the same problem while messing around with heroku. All the paths seemed to be there. Running Ubuntu 12.04 and I even created a sym link for gmake. Nothing fixed it. I tried this eventually

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

instead of

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

and this seemed to fix it and make heroku happy. If you find a proper solution, do let me know.

Upvotes: 0

Laurent Perrin
Laurent Perrin

Reputation: 14881

Heroku is failing to build hiredis. The reason is that hiredis (the node.js module) depends on hiredis (the C library), which needs GNU make, which is not available on your slug.

Question is, why is NPM trying to build hiredis while it's not in your dependencies ?

You should check if hiredis appears anywhere in your project (grep -R hiredis .). Another possibility is that Heroku is trying to provide redis to all node.js apps ?

I'd check with Heroku's support.

Upvotes: 2

Related Questions