1

I have 2 servers with exactly the same setup. But on 1 server I ran against an error and on another server it works well.

On server 1 :

[root@tst socketio]# npm list socket.io
/var/socketio
└── [email protected] 

Package nodejs-0.10.48-3.el6.x86_64 already installed and latest version

On server 2 :

[root@1 socketio]# npm list socket.io
/var/socketio
└── [email protected] 

Package nodejs-0.10.48-3.el6.x86_64 already installed and latest version

Script on server 1 :

[root@tst socketio]# node /var/socketio/socketioclient.js 1768
Time: 5/3/2018 21:10:6
ID: 1768
Start connect
S-connection
k95RAgJVnhzv4ItHABvu
S-emit event
S-disconnect

Script on server 2 :

[root@1 socketio]# node /var/socketio/socketioclient.js 1768
Time: 5/3/2018 20:59:24
ID: 1768

/var/socketio/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js:66
  var headers = Object.assign({}, defaultHeaders);
                       ^
TypeError: Object function Object() { [native code] } has no method 'assign'
    at new XMLHttpRequest (/var/socketio/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js:66:24)
    at /var/socketio/node_modules/socket.io-client/node_modules/engine.io-client/lib/transports/polling.js:24:13
    at Object.<anonymous> (/var/socketio/node_modules/socket.io-client/node_modules/engine.io-client/lib/transports/polling.js:26:3)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/var/socketio/node_modules/socket.io-client/node_modules/engine.io-client/lib/transports/polling-xhr.js:6:15)

My socketioclient.js :

console.log(datetime);
console.log('ID: '+ID);
var io = require('socket.io-client');
console.log('Start connect');
var sSocket = io.connect('https://11.22.33.44:1234', {
    reconnection: true,
    reconnectionDelay: 1000,
    reconnectionDelayMax : 5000,
    reconnectionAttempts: 3
});
sSocket.on('connect', function (data) {

    console.log('S-connection');
    console.log(sSocket.id);

        console.log('S-emit event');
        sSocket.emit('event', { ID: ID });
        sSocket.disconnect();

    }

    sSocket.on('serveroutput', function (data) {
        console.log('S-serveroutput: '+data);
    });

});

sSocket.on('disconnect', function (data) {
    console.log('S-disconnect');
});

sSocket.on('reconnect', function() {
    console.log('S-reconnecting');
});

sSocket.on('reconnect_failed', function (data) {
    console.log('S-reconnect failed');
});

I see no difference in socketio version or in nodejs version. But the outcome is different. How come ?

I have read (on this website) about needing node version >= 4. But as it works on 1 server I don't think this is the issue here.

0

1 Answer 1

1

tl;dr Upgrade to the most recent Node LTS release (currently 8)

It looks like you have different versions of xmlhttprequest-ssl, even though the parent socket.io is at 2.0.4. xmlhttprequest-ssl version 1.5.4 or newer includes the use of Object.assign. Versions from 1.5.2 down might work better in Node 0.10.

If you look at the paths in the stack trace, there are a number of modules other than socket.io involved in the error:

socket.io-client/node_modules/engine.io-client/node_modules/xmlhttprequest-ssl

The npm command supported on Node 0.10 is non deterministic which means you can end up with two installs of the same parent module but they are made up from different child dependencies. This largely depends on when you ran the npm install as to what versions you get.

Recent versions of npm (5.x) and the yarn package manager now support lock files that fully describe an applications dependencies and will be able to create consistent installs over time.

A lot of modules have started dropping support for any Node versions prior to 4.x so this type of error is going to become more and more common for Node 0.x users.

Use the current Long Term Support release of Node. If you require packages for your RHEL platform, Nodesource provide rpms.

Sign up to request clarification or add additional context in comments.

4 Comments

Should I first remove socket.io (npm uninstall socket.io) ? Should I also remove node.js completely (yum erase nodejs ) ? Before installing the new Node LTS version.
I believe the packages won't coexist, so yes you will probably need to remove the old one. If you can do the node upgrade on a test server, rm -rf node_modules and npm install will get everything up to date. Confirm the app all works. Then you will have a package-lock.json that describes a working set of dependencies that you can use where ever you need to do the install.
I have succesfully removed npm and then nodejs. Then succesfully re-installed nodejs-8.10.0 with yum (Package 2:nodejs-8.10.0-1nodesource.x86_64 already installed and latest version ). But now I can not install npm any more. I get all sorts of conflicts, like this : file /usr/lib/node_modules/npm/node_modules/sha from install of npm-1.3.6-5.el6.noarch conflicts with file from package nodejs-2:8.10.0-1nodesource.x86_64 And also : file /usr/lib/node_modules/npm/node_modules/which conflicts between attempted installs of npm-1.3.6-5.el6.noarch and nodejs-2:8.10.0-1nodesource.x86_64
Apparently npm was not removed. I could issue the following command : npm install npm@latest -g. This solved my problem with the conflicts and everything works well now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.