Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Error: Cannot find module" when using browserify to bundle a socket.io dependency with --node flag

I'm trying to use browserify to bundle my server side code into a single JS file. Hence I'm running

browserify --node -t coffeeify source/server.js.coffee -o deployment/server.js 

But I'm getting the following error

Error: Cannot find module '../build/Release/bufferutil' from '/My/Project/Path/node_modules/socket.io/node_modules/engine.io/node_modules/ws/lib'

The only offending line seems to be the require "socket.io". When I remove it the bundling works fine. It also works fine if I remove the --node flag.

The "missing" module appears to be there when I check the directory with

ls node_modules/socket.io/node_modules/engine.io/node_modules/ws/build/Release/

I see

.deps/           bufferutil.node* linker.lock      obj.target/      validation.node*

Some googling led me to this https://github.com/websockets/ws/issues/25. But that seems to be referring to an old version of ws. The version of ws in the module is already beyond that and I've also already tried rebuilding node from source as recommended but to no avail.

Any idea what could still be causing this error?

like image 812
fynyky Avatar asked Mar 16 '23 22:03

fynyky


1 Answers

I run into the same problem and I have error first with bufferutil then with utf-8-validate, but according to this Readme.md, you need to install them as requirements with --save options. Hope this helps.

There are 2 optional modules that can be installed along side with the ws module. These modules are binary addons which improve certain operations, but as they are binary addons they require compilation which can fail if no c++ compiler is installed on the host system.

  • npm install --save bufferutil: Improves internal buffer operations which allows for faster processing of masked WebSocket frames and general buffer operations.

  • npm install --save utf-8-validate: The specification requires validation of invalid UTF-8 chars, some of these validations could not be done in JavaScript hence the need for a binary addon. In most cases you will already be validating the input that you receive for security purposes leading to double validation. But if you want to be 100% spec-conforming and have fast validation of UTF-8 then this module is a must.

like image 83
lowselfesteemsucks Avatar answered Apr 25 '23 21:04

lowselfesteemsucks