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

Dependencies bufferutil and utf-8-validate are listed as devDependencies #659

Closed
TheLudd opened this issue Jan 8, 2016 · 13 comments
Closed

Comments

@TheLudd
Copy link

TheLudd commented Jan 8, 2016

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?

@3rd-Eden
Copy link
Member

3rd-Eden commented Jan 8, 2016

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 notifications@github.com 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.

@janhoogeveen
Copy link

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.

@TheLudd
Copy link
Author

TheLudd commented Jan 8, 2016

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?

@janhoogeveen
Copy link

Check socketio/socket.io-client#933

@3rd-Eden
Copy link
Member

3rd-Eden commented Jan 9, 2016

@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.

@3rd-Eden 3rd-Eden closed this as completed Jan 9, 2016
tkurki added a commit to SignalK/freeboard-sk that referenced this issue Dec 17, 2016
For some reason browserify complained about mdns, which definitely is not
needed in browser environment. Ws has bufferutil and utf-8-validate as
optional dependencies, but browserify fails on them, so ignore them.
See websockets/ws#659.
Fix also bundle generation, the pipe looks like a bug or some
shell specific feature(?). This produces 3.5M bundle.js.
@wayofthefuture
Copy link

wayofthefuture commented Jun 26, 2017

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.

@3rd-Eden
Copy link
Member

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

@wayofthefuture
Copy link

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

@3rd-Eden
Copy link
Member

Yes

@wayofthefuture
Copy link

Thank you for your time.

@fabcotech
Copy link

fabcotech commented Sep 10, 2019

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 :).

@swissmanu
Copy link

swissmanu commented May 15, 2021

for what its worth: with rollup, you can configure the commonjs plugin to ignore bufferutil and utf-8-validate and leave their require statements untouched:

import commonJs from '@rollup/plugin-commonjs';

// rollup.config.js
{
  plugins: [
    commonJs({
      ignore: ['bufferutil', 'utf-8-validate'], // Ignore optional peer dependencies of ws
    }),
  ]
}

for me, this resolved this problem.

@sebbean
Copy link

sebbean commented Jan 5, 2025

ty @swissmanu helped me out!

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

7 participants