question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

4.3.0 Buffer is not defined

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
darrachequesnecommented, Nov 14, 2021

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

This should be (finally!) fixed by https://github.com/socketio/engine.io-client/commit/9fcaf58d18c013c0b92fdaf27481f0383efb3658, included in engine.io-client@6.0.3 and socket.io-client@4.3.2 by transitivity.

Please reopen if needed.

0reactions
Murderloncommented, Nov 10, 2021

We are running into this problem when users are building Uppy with Vite: https://github.com/transloadit/uppy/issues/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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught ReferenceError: Buffer is not defined - Stack Overflow
Answering my own question. Two things helped to resolve the issue: Adding plugins section with ProviderPlugin into webpack.config.js.
Read more >
cannot read properties of undefined (reading 'buffer') - You.com
It means the file is not parsed, which means the request is not correct. Change data property to include only formData , no...
Read more >
Converse.js API Documentation Source: headless/dist ...
"If buffer is not empty, it contains either 12 or 18 bits. ... should not be hit in tests return index < 0...
Read more >
Changelog - Cypress Documentation
This previously resulted in unusual and undefined behavior. ... We fixed a regression in 4.3.0 where the message output during errors were not...
Read more >
exceljs - npm
Latest version: 4.3.0, last published: a year ago. Start using exceljs in your project ... To freeze rows only, set this to 0...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found