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

4.3.0 Buffer is not defined #1504

Closed
faradaytrs opened this issue Oct 15, 2021 · 9 comments
Closed

4.3.0 Buffer is not defined #1504

faradaytrs opened this issue Oct 15, 2021 · 9 comments
Labels
bug Something isn't working

Comments

@faradaytrs
Copy link

faradaytrs commented Oct 15, 2021

Describe the bug

After i compile app in production mode in vite (it uses rollup). I get the following error:
Buffer is not defined at constants.js:5
Socket.IO client version: 4.3.0

Platform:

  • Device: iMac late 2015
  • OS: MacOS

Additional context

I use Vercel for compilation, but i think problem is not with Vercel

@faradaytrs faradaytrs added the bug Something isn't working label Oct 15, 2021
@darrachequesne
Copy link
Member

Arf, now that the dev build is fixed (socketio/engine.io-client@4971914), it's the production build that fails... I'm digging into this.

darrachequesne added a commit to socketio/engine.io-parser that referenced this issue Oct 15, 2021
Some bundlers (like vite) do not support having a "browser" field in a
nested package.json.

Related: socketio/socket.io-client#1504
darrachequesne added a commit to socketio/engine.io-client that referenced this issue Oct 15, 2021
Some bundlers (like vite) do not support having a "browser" field in a
nested package.json.

Note: the previous commit ([1]) fixed the resolution of the "browser"
field in the dev bundle, but the production bundle still failed.

Related: socketio/socket.io-client#1504

[1]: 4971914
@darrachequesne
Copy link
Member

It should be fixed in latest version (4.3.1), could you please check?

@faradaytrs
Copy link
Author

Nope it's still the same. And error is in runtime, not during the build.

@darrachequesne
Copy link
Member

@faradaytrs I cannot reproduce with latest version: https://github.com/socketio/socket.io-fiddle/tree/vite

Could you please check?

@tcastelly
Copy link

Hello,

I had the same issue even after the fix (4.3.2).
It was my fault;

I use socket.io-client in a third party library. This library has socket.io-client as peerDependencies. I have two builds:

  • my-lib.es.js
  • my-lib.umd.js

My main project used the umd instead of the es, after change to use the es it works!

The repo to reproduce.

@faradaytrs
Copy link
Author

I have similar situation with @tcastelly, but my dependency doesn't have esm build. It relies on socket.io-client as peer dependency though.

@faradaytrs
Copy link
Author

After I updated dep to use esm it works, but I believe it might be a problem in many cases for many people.

@Murderlon
Copy link

We are running into this problem when users are building Uppy with Vite: transloadit/uppy#3265. It's currently blocking people from going to production.

I investigated and this seems to be a dual publishing issue. If you import socket.io-client in ESM then everything works fine. But if you are importing it indirectly through commonjs, then socket.io-client ships Buffer to the browser, which will fail.

Here is a minimal reproducible example:

vite-socketio.zip

Note: this zip includes the node_modules because I added a fake-package folder in there with a package.json and index.js.

The index.js only does this:

const io = require('socket.io-client')

module.exports = io

To see the error:

  1. Download and extract zip
  2. Do not run npm install
  3. npm run build && npm run preview
  4. See error in the console.

As this is blocking our customers I'm willing to contribute to fix this but I would need some pointers to get started. As far as I know the buffer usage comes from engine.io-client.

darrachequesne added a commit to socketio/engine.io-parser that referenced this issue Nov 14, 2021
darrachequesne added a commit to socketio/engine.io-client that referenced this issue Nov 14, 2021
darrachequesne added a commit to socketio/engine.io-client that referenced this issue Nov 14, 2021
@darrachequesne
Copy link
Member

darrachequesne commented Nov 14, 2021

@Murderlon I could indeed reproduce the issue, thanks a lot for the sample project 👍

This should be (finally!) fixed by socketio/engine.io-client@9fcaf58, included in [email protected] and [email protected] by transitivity.

Please reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants