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

青春壹個敷衍的年華 提交于 2019-12-07 09:14:51

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/30475215/error-cannot-find-module-when-using-browserify-to-bundle-a-socket-io-dependen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!