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

Unable to bundle socket.io client due to undeclared dependency on base64-arraybuffer #116

Closed
ozyman42 opened this issue Nov 30, 2020 · 6 comments

Comments

@ozyman42
Copy link

I'm attempting to bundle the socket.io client with webpack 5 and yarn 2. I believe these have more strict dependency checks which would explain why this issue hasn't been opened for webpack 4 and/or npm users.

Webpack is giving the error

ERROR in ../../../.yarn/cache/engine.io-parser-npm-4.0.1-6bdb879e8a-3b71ef8b5a.zip/node_modules/engine.io-parser/lib/decodePacket.browser.js 7:18-47
Module not found: Error: engine.io-parser tried to access base64-arraybuffer, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: base64-arraybuffer (via "base64-arraybuffer")
Required by: engine.io-parser@npm:4.0.1 (via /home/alex/GitProjects/tools/webpack-hot-module-replacement/.yarn/cache/engine.io-parser-npm-4.0.1-6bdb879e8a-3b71ef8b5a.zip/node_modules/engine.io-parser/lib/)
 @ ../../../.yarn/cache/engine.io-parser-npm-4.0.1-6bdb879e8a-3b71ef8b5a.zip/node_modules/engine.io-parser/lib/index.js 2:21-46
 @ ../../../.yarn/cache/engine.io-client-npm-4.0.2-9adb255344-af3880585b.zip/node_modules/engine.io-client/lib/index.js 14:24-51
 @ ../../../.yarn/cache/socket.io-client-npm-3.0.3-512b232ec1-8bb891554f.zip/node_modules/socket.io-client/build/manager.js 4:12-39
 @ ../../../.yarn/cache/socket.io-client-npm-3.0.3-512b232ec1-8bb891554f.zip/node_modules/socket.io-client/build/index.js 5:18-38 69:16-36
 @ ../../@skoville/webpack-hmr/client/universal/default-socket-io-accessor~/build/socket-io-accessor.js 13:27-54
 @ ../../@skoville/webpack-hmr/client/universal/default-socket-io-accessor~/build/package.js 13:13-44
 @ ../../@skoville/webpack-hmr/client/web/default~/build/entry.js 13:66-142

seems like this is accurate since it's being required here

base64decoder = require("base64-arraybuffer");

is there any reason why this isn't included in dependencies and is instead only in devDependencies?

"base64-arraybuffer": "0.1.5",

In case there's a native component to this library which causes it to fail compiling for some users, consider following the approach that was eventually taken here websockets/ws#1220, where we would move base64-arraybuffer from devDependencies to optionalDependencies.

I can open a PR if this approach (move to optional dependencies) works for you.

@ozyman42
Copy link
Author

Looking at base64-arraybuffer, it appears to be a pure JavaScript implementation, so I don't see a reason why it can't just be directly added to dependencies

@darrachequesne
Copy link
Member

base64-arraybuffer in the devDependencies list, because the engine.io-parser package is used by both the Engine.IO server and client (which itself can be used in the browser and in Node.js) but is only necessary for the client, so it is listed in the dependencies here: https://github.com/socketio/engine.io-client/blob/4.0.4/package.json#L27

Now, it seems yarn v2 is indeed a bit more strict: https://dev.to/arcanis/introducing-yarn-2-4eh1#strict-package-boundaries

I guess we'll have to remove this "optimization" to support yarn v2.

darrachequesne added a commit that referenced this issue Dec 7, 2020
The dependency was previously only listed as dev dependency, so that it
was not included when installing the server (the "engine.io" package,
which does not require it) and was explicitly included by the client
(the "engine.io-client" package, which needs it for the browser build).

But it failed with yarn v2, due to its stricter package boundaries:

> ERROR in ../../../.yarn/cache/engine.io-parser-npm-4.0.1-6bdb879e8a-3b71ef8b5a.zip/node_modules/engine.io-parser/lib/decodePacket.browser.js 7:18-47
> Module not found: Error: engine.io-parser tried to access base64-arraybuffer, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

> Required package: base64-arraybuffer (via "base64-arraybuffer")
> Required by: engine.io-parser@npm:4.0.1 (via xxx/.yarn/cache/engine.io-parser-npm-4.0.1-6bdb879e8a-3b71ef8b5a.zip/node_modules/engine.io-parser/lib/)

Related:

- https://dev.to/arcanis/introducing-yarn-2-4eh1#strict-package-boundaries
- #116
@darrachequesne
Copy link
Member

Closed by 2ccdeb2 (included in engine.io-parser@4.0.2)

@dawsbot
Copy link

dawsbot commented Feb 2, 2022

I'm getting this error once-again on a newer version of this library.

I had to revert from "socket.io-client": "^4.4.1" to "socket.io-client": "^4.4.0". This is a Next.js project, and Vercel cannot run the next build command when the client is 4.4.1. Any clue why this fix works?

@darrachequesne
Copy link
Member

@dawsbot base64-arraybuffer was replaced by @socket.io/base64-arraybuffer in 25a4b2b. Could it be linked?

@dawsbot
Copy link

dawsbot commented Feb 18, 2022

@darrachequesne I'm not sure if that relates, it sounds likely. I'm unable to create a reproduction repo for you with my current schedule, but I appreciate the response 🙏

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