Ws: Dependencies bufferutil and utf-8-validate are listed as devDependencies

Created on 8 Jan 2016  Â·  11Comments  Â·  Source: websockets/ws

My app has this library as a child dependency. I can currently not start it since I get errors saying that module bufferutil and utf-8-validate cannot be found. The errors originate from this module I notice that the two dependencies are listed as devDependencies. Could they be included as regular dependencies?

Most helpful comment

I just found a solution.

The problem has been described above : those two libraries are not at all required by ws module. So the problem is that some bundlers (mine is rollup) still try to resolve it, and if they do not resolve it, you have a Cannot find module 'bufferutil' or similar error at runtime.

My simple solution was simply to create fake modules in my node_modules folder.

mkdir ./node_modules/bufferutil/ && touch ./node_modules/bufferutil/index.js
mkdir ./node_modules/utf-8-validate/ && touch ./node_modules/utf-8-validate/index.js

Then those two modules will be indluded in your bundle and an import or require will not crash :).

All 11 comments

No, they are dev dependencies, nothing in this library depends directly on it. The error is somewhere in your own code or the library that consumes this library.

Arnout Kazemier

On Jan 8, 2016, at 4:02 PM, Ludwig Magnusson [email protected] wrote:

My app has this library as a child dependency. I can currently not start it since I get errors saying that module bufferutil and utf-8-validate cannot be found. The errors originate from this module I notice that the two dependencies are listed as devDependencies. Could they be included as regular dependencies?

—
Reply to this email directly or view it on GitHub.

For what it's worth, I had the same trouble in my custom version of https://github.com/erikras/react-redux-universal-hot-example and removing everything related to Socket.IO got rid of all the errors. Maybe worth investigating if they have new minor/patch versions released that got automatically updated.

Yes I now understand that the error occurs when browserify is used with this project. It does not handle the try-catch around the non existing dependencies. Is there a good solution for handling this?

@TheLudd It's really a bug in browserify for not understanding conditional imports.

Anyways, i'm going to close this bug for now. If there are concrete fixes that I can do in this module to make bundling easier, feel free to give me a poke.

Just installed 3.0.0, can't even get it to build with webpack. Same error.

import WebSocket from 'ws';

This is client-side browser code. Am I not suppose to use the 'ws' lib client-side? Should I use the native browser implementation?

Is this incorrect?
Thanks for your help.

This is a node client, not a front-end library.

@3rd-Eden So I should just use native websocket?

Yes

Thank you for your time.

I just found a solution.

The problem has been described above : those two libraries are not at all required by ws module. So the problem is that some bundlers (mine is rollup) still try to resolve it, and if they do not resolve it, you have a Cannot find module 'bufferutil' or similar error at runtime.

My simple solution was simply to create fake modules in my node_modules folder.

mkdir ./node_modules/bufferutil/ && touch ./node_modules/bufferutil/index.js
mkdir ./node_modules/utf-8-validate/ && touch ./node_modules/utf-8-validate/index.js

Then those two modules will be indluded in your bundle and an import or require will not crash :).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jorenvandeweyer picture jorenvandeweyer  Â·  4Comments

quesurifn picture quesurifn  Â·  3Comments

sherikapotein picture sherikapotein  Â·  3Comments

nabeelio picture nabeelio  Â·  5Comments

brainkim picture brainkim  Â·  4Comments