Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error running a nodejs server on a Mac, 'no suitable image found'

unknown406c8f2d5ecb:proves airrider3$ node tronServer.js
[Error: dlopen(/Users/airrider3/Documents/proves/node_modules/now/node_modules/node-proxy/build/Release/nodeproxy.node, 1): no suitable image found.  Did find:
    /Users/airrider3/Documents/proves/node_modules/now/node_modules/node-proxy/build/Release/nodeproxy.node: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00]
Error: dlopen(/Users/airrider3/Documents/proves/node_modules/now/node_modules/node-proxy/build/Release/nodeproxy.node, 1): no suitable image found.  Did find:
    /Users/airrider3/Documents/proves/node_modules/now/node_modules/node-proxy/build/Release/nodeproxy.node: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00
    at Object.Module._extensions..node (module.js:485:11)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (/Users/airrider3/Documents/proves/node_modules/now/node_modules/node-proxy/lib/node-proxy.js:1:90)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

It worked perfectly in Linux. I've just installed nodejs, nowjs, etc, runned this server script, but it keeps throwing this error.

Any ideas?

Server code: (it's kind of a tron multiplayer game)

var html = require('fs').readFileSync(__dirname + '/tronMultiplayer.html');
var server = require('http').createServer(function (req, res) {
   res.end(html);
});
server.listen(8004);

var nowjs = require('now');
var everyone = nowjs.initialize(server);

var bikes = {};
var killCount = {};
var player = 0;

var EMPTY = -1;
var WALL = -2;

var map = [];
var edge = 100;

var count = 0;
var deadbikes = 0;

var gameON = false;




function resetGame () {

    map = [];
    for (var i = 0; i < edge; i++){
        map.push([]);
        for (var j = 0; j < edge; j++){
            if (i == 0 || j == 0 || i == edge-1 || j == edge-1/* || Math.floor(Math.random()*30) == 0*/){
                map[i].push(WALL);
            } else {
                map[i].push(EMPTY);
            }
        }
    }   

    for (var i in bikes){
        spawnBike(i)
    }   
    everyone.now.reset(edge);
    everyone.now.updateScores(bikes);
}

nowjs.on('connect', function () {
   console.log('connect');
   bikes[this.user.clientId] = {nick: "Anonymous", w:0, i: Math.floor(Math.random()*edge-2)+1, j: Math.floor(Math.random()*edge-2)+1, di : 0, dj : 1, p: player, c: "rgba("+Math.floor(Math.random()*255)+ ", " + Math.floor(Math.random()*255)+","+Math.floor(Math.random()*255)+", 1)", alive : false};
   killCount[this.user.clientId] = 0;
   player++;
   console.log(this.user.clientId);
   console.log(bikes);
   if (!gameON){
    gameON = true;
    resetGame();
    step();
   }
});

everyone.now.changeBikeDirection = function (dir) {
    console.log(bikes[this.user.clientId].nick + " changes his direction to " + dir);
    var ndi = 0, ndj = 0;
    if (dir == "left"){
        ndj = -1;
    } else if (dir == "right"){
        ndj = 1;
    } else if (dir == "up"){
        ndi = -1;
    } else if (dir == "down"){
        ndi = 1;
    }
    var odi, odj;
    odi = bikes[this.user.clientId].di;
    odj = bikes[this.user.clientId].dj;

    if (odi != ndi && odj != ndj) {
        bikes[this.user.clientId].di = ndi; 
        bikes[this.user.clientId].dj = ndj;
    }
    killCount[this.user.clientId] = 0; 
};

everyone.now.updateNickname = function (theName) {
    bikes[this.user.clientId].nick = theName;
    everyone.now.updateScores(bikes);
};

function spawnBike (k) {
    bikes[k].i =  Math.floor(Math.random()*edge*(2/4) -2)+1 + edge/4;
    bikes[k].j = Math.floor(Math.random()*edge*(2/4)  -2)+1 + edge/4;
    bikes[k].di = 0;
    bikes[k].dj = 1;
    bikes[k].alive = true;
    player++;
}

nowjs.on('disconnect', function () {
   console.log(bikes[this.user.clientId].nick + ' has disconnected.');
   for (var i in bikes) {
      if (i === this.user.clientId) {
         killBike(i);
     delete bikes[i];
         break;
      }
   }
});

function killBike(k){
        var bike = bikes[k];
    bike.alive = false;
    for (var i = 0; i < edge; i++){
        for (var j = 0; j < edge; j++){
            if (map[i][j] == bike.player){
                map[i][j] = EMPTY;
            }
        }
    }
    //delete bikes[k];
}

function checkIfBikeIsDead(k){
        //console.log("CheckIfBikeIsDead with id "+k);
    var bike = bikes[k];
    if (bike.alive){
        //console.log("Checking current position");
        if (map[bike.i][bike.j] != EMPTY){
            //console.log("Ouch, Cell was "+map[bike.i][bike.j]);
            bike.i -= bike.di;
            bike.j -= bike.dj;
            killBike(k);

            for (var i in bikes){
                if (i != k){
                    if (bikes[i].alive){
                        bikes[i].w++;
                    }
                }
            }
            everyone.now.updateScores(bikes);           
            return true;
        } else {
            //console.log("Safe and sound");
            map[bike.i][bike.j] = bike.p;
            return false;
        }
    } else {
        return false;
    }

}

function traceMap() {
    console.log("---------------------------------------------------------------------");
    var s = "";
    for (var i = 0; i < edge; i++){
        s = "[";
        for (var j = 0; j < edge; j++){
            if (map[i][j] == undefined){
                console.log("We found an undefined at ("+i+","+j+")");
            } else {
                s += map[i][j].toString() + ", ";
            }
        }
        s += "]";
        console.log(s);
    }
}

function step () {

    count = 0;
    deadbikes = 0;

    for (var k in bikes){
        killCount[k]++;
        if (killCount[k] > 2000){
            killBike(k);
            delete bikes[k];
        } else {
            count++;
            if (bikes[k].alive){
                bikes[k].i += bikes[k].di;
                bikes[k].j += bikes[k].dj;
                if (checkIfBikeIsDead(k)){
                    deadbikes++;
                }
            } else {
                deadbikes++;
            }
        }
    }

    if (count > 0){
        if (count == deadbikes){
        resetGame();
        }
        setTimeout(step, 50);
        everyone.now.receiveNewPositions(bikes);
    //  traceMap();
    } else {
        gameON = false;
    }


}
like image 848
David Da Silva Contín Avatar asked Jul 30 '12 09:07

David Da Silva Contín


People also ask

How do I run node JS Server on Mac?

js file on Mac, you need to download the installer package from the Node. js official website first and set it up by following the on-screen instructions on your system. Then, you've to create a . js file and run it using the node command on Mac.

How do I know if my node server is running Mac?

To see if Node is installed, type node -v in Terminal. This should print the version number so you'll see something like this v0. 10.31 . To see if NPM is installed, type npm -v in Terminal.

How do I open a node JS terminal on a Mac?

Open the Terminal by pressing Command+Space to open Spotlight Search and entering Terminal then pressing Enter . Enter node - v in the Terminal and press Enter .


2 Answers

Nevermind. Facepalm. The node_modules folder I had was the same that I used/installed in Linux, so I believe that some parts were compiled specifically for Linux, or whatever.

Solved by erasing the node_modules folder and reinstalling.

I hope it helps to anyone with the same doubt!

like image 162
David Da Silva Contín Avatar answered Sep 28 '22 17:09

David Da Silva Contín


Follow David Da Silva Contín's answer is great!

$ sudo rm -rf node_modules/
$ npm install
like image 22
Lane Avatar answered Sep 28 '22 17:09

Lane