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.

Uncaught ReferenceError: Buffer is not defined

See original GitHub issue

Hi! I’m having this weird error message using Vite as a bundler which seems to happen in a very specific scenario.

I couldn’t reproduce it using the default vite dev server (ie.: npx vite), but I managed to create a small repro of the scenario I have in another project that uses Phoenix and does not use vite’s dev server.

I can confirm though that the error only happens when the last import is present (@uppy/transloadit):

import Uppy from '@uppy/core'
import Dashboard from '@uppy/dashboard'
import Transloadit from '@uppy/transloadit'

image


Creating an simple HTML file and adding a script tag to the head works fine using vite’s dev server (npx vite):

index.html

<script type="module">
  import Uppy from '@uppy/core'
  import Dashboard from '@uppy/dashboard'
  import Transloadit from '@uppy/transloadit'
<script>

But it doesn’t work if I use vite build with my current config for some reason. Here’s a small repro that illustrates the problem: vite-repro.zip

Instructions:

  • npm i --prefix assets
  • npm run build --prefix assets
  • npm run start --prefix assets (for the HTTP server).
  • See error in Chrome dev tools (I’m using version 94.0.4606.81)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:21 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
Murderloncommented, Nov 10, 2021

It was a bit of a confusing process to reproduce this with only socket.io-client and not through @uppy/transloadit but I did in the end. I reported it to them (see reference above) and offered interest in contributing, but it seems I can’t fix this on our side as it seems to be a dual publishing issue on their end.

3reactions
RobWalkercommented, Nov 9, 2021

@thiagomajesk my current work around is to load uppy from the CDN rather than bundle it via vite, basically add:

<script src="https://releases.transloadit.com/uppy/v2.2.3/uppy.min.js"></script>

to index.html and then use window.Uppy to reference it from the code … it is far from ideal, but it does work and our project still has a ways to go before hitting production and we can punt on this for a little longer in the hope of a more formal fix.

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 >
Uncaught ReferenceError: Buffer is not defined #1626 - GitHub
Trying to bundle a project which includes https://solana-labs.github.io/wallet-adapter. First, I had a problem with global not being defined ...
Read more >
Buffer is not defined. Using Phantom Wallet, Solana and ...
I pick a working project from a friend and set mine to have the same settings. What I could say for sure is...
Read more >
How to polyfill Buffer with Webpack 5 - viglucci.io
The "buffer is not defined" error is a common error that can occur when trying to use the Buffer Node.js API in an...
Read more >
ReferenceError: Buffer is not defined - Homey Community Forum
:x: Script Error :warning: ReferenceError: Buffer is not defined at connectToWallbox (wallbox.js:25:35) at wallbox.js:131:19 at processTi…
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