Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket.io server - require.resolve() #289

Closed
a-lucas opened this issue Dec 30, 2016 · 4 comments
Closed

Socket.io server - require.resolve() #289

a-lucas opened this issue Dec 30, 2016 · 4 comments

Comments

@a-lucas
Copy link

a-lucas commented Dec 30, 2016

I have been going trough all issues so far, and googling a bit.

In Socket.io source code, they use require.resolve, which is not supported by browserify.

So I excluded 'socket.io' from nexe.browserify.excludes in the package.json file.

I tried to create a node_modules folder inside the generated bin folder, with no luck. "Can;t find native module" it says. The problem is that socket.io is not a native module anymore, just plain JS files.

Is there a way to include unsupported files alongside the generated bin? is the solution to list every single file required by socket.io inside the requiredFiles array ?

I will now try to replace require.resolve by something else and see if that fixes it. I'll keep you updated with this.

@a-lucas
Copy link
Author

a-lucas commented Dec 30, 2016

I fixed it by hacking socket.io source code :

Edit the file socket.io/lib/index.js

At the top:

var exists = require('fs).existsSync;

Then replace the problematic code with :


  if (v && !clientSource) {

    var clientSourcePath = path.resolve(__dirname, './../../socket.io-client/dist/socket.io.min.js');
    var clientSourceMapPath = path.resolve(__dirname, './../../socket.io-client/dist/socket.io.min.js.map');
    if(!exists(clientSourcePath)) {
      throw new Error('Cannot load socket.io.min.js');
    }
    if(!exists(clientSourceMapPath)) {
      debug('could not load sourcemap file');
    } else {
      clientSourceMap = read(clientSourceMapPath);
    }
    clientSource = read(clientSourcePath);


/*
    clientSource = read(require.resolve('socket.io-client/dist/socket.io.min.js'), 'utf-8');
    try {
      clientSourceMap = read(require.resolve('socket.io-client/dist/socket.io.js.map'), 'utf-8');
    } catch(err) {
      debug('could not load sourcemap file');
    }
*/
  }

@a-lucas
Copy link
Author

a-lucas commented Dec 30, 2016

Closing as I just submitted a PR to socket.io project.

socketio/socket.io#2797

@a-lucas a-lucas closed this as completed Dec 30, 2016
@khuongduybui
Copy link

I'm using nexe 2.0.0-rc.22 and socket.io 2.0.4 and I still get the require.resolve error with the default setting (giving only an index.js entry point).

What exactly should I config to get this to work?

@calebboyd
Copy link
Member

Huh, weird. The call to require.resolve (in socket.io code) is completely unnecessary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants