Uncaught ReferenceError: Buffer is not defined
See original GitHub issueHi! 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'
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:
- Created 2 years ago
- Comments:21 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.@thiagomajesk my current work around is to load uppy from the CDN rather than bundle it via vite, basically add:
to
index.html
and then usewindow.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.