-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Uncaught ReferenceError: Buffer is not defined #3265
Comments
Hi, @thiagomajesk. As I initially expected, this is not an issue with Uppy but a bundler issue. I'm not familiar with bundlers so it left me confused for a bit so pardon me for the late reply. We don't use |
Hi @Murderlon, thanks a lot for looking into it. I was in fact expecting that this could be a Vite issue because of how it serves modules as-is but wasn't sure... My tests were inconclusive because, here's the weird part: I've managed to make it work purely with I also stumbled upon many discussions like vitejs/vite#3126 (comment) and vitejs/vite#728 (comment) and I don't know what I should make of that information when I read the following statements from the project maintainers: I'll try to follow your advice on the shimming process, but in the meantime, If we can confirm that this is in fact related to Vite alone I'll proceed to open an issue on their repo so we can get investigate it further. |
Hi, I don't think another issue in Vite will help here as it is the same problem as has been surfaced in multiple discussions, unless it's specifically around trying to work around this instance. We are considering patching Regarding the response from the maintainers from Vite, I agree with the sentiment, but it's a very unnuanced take as it's not always feasible to "swap it out with something more modern". We rely heavily on Lastly, |
I ran into this issue in a Vue 3 project, and the best workaround I found was to defer the loading of the components that relied on Uppy. In my case all the Uppy code was within an
to
Caused the production vite build to bundle those libraries separately ... and everything just worked. I don't quite understand /why/ it works at runtime with this approach vs a single bundle since Buffer is still undefined. As far as this Uppy is concerned to @Murderlon point ... it would be ideal if socket.io could be more selective even if only because it sounds like a bunch of unused code is getting loaded/executed which is never ideal in the browser. |
@Murderlon Sorry for the delay... I tried going the shimming route using import polyfillNode from 'rollup-plugin-polyfill-node'
export default {
plugins: [polyfillNode()],
optimizeDeps: { exclude: ["@uppy/*"]}
// [...]
} While building I get this error:
Alternatively, I also tried making buffer available on
One of the errors I get when I try to manually polyfill buffer:
My impression so far is that It seems there isn't a straight-up solution for this or I'm solving the wrong problem. I'm also not a bundler expert, so I'm missing whether this could be considered just a bundling issue or a package delivery problem. For what is worth, I've also searched a little more and it seems people using Webpack had similar problems because Webpack 5 does shim buffer and friends by default: |
@thiagomajesk I can confirm that this happened to us as well. Started from the Buffer error then when we tried polyfilling Buffer, it then raised the error regarding the missing "Writeable", which turned out, on further inspection, to be an empty module. I also tried using terser instead of esbuild for minification but to no avail. It's weird that the error only happens in build and not on dev. At this point we'll probably ditch the Transloadit Plugin and look for alternatives as this broke the entire app we're working on. |
After some research, edit: |
Thanks for the detailed updates. We are discussing this internally at the moment how to best solve this. I will post an update once we have something. |
We're now running into this again at runtime: hitting the same issue as @thiagomajesk with Attempts to polyfill it have all fallen flat or lead down a rabbit hole of other errors. It looks like it comes down to using vite or the transloadit plugin and we can't ditch vite easily, so we will also need to look for another option 😞 Definitely frustrating since the code itself works fine in a dev build, so the problem seems to be that too much code is getting run in production which is not what we want! |
This was one of the confusing parts. We have two apps, one that experiences this problem, the other doesn't and works seamlessly. Both uses the same code for uppy and its components. It's weird as to which of these should be approached to find the solution. |
@RobWalker I don't think Vite is the problem anymore. Since Webpack 5 doesn't do shims out of the box as well, I figure folks over there would have the same problems we are having. Even shimming with the same lib is not working for some reason.
I'd start investigating why it works differently with
Could you share a minimal repro of your apps as well @lxsmnsyc? I think it would help. |
Try out this example: If you run just If you run |
This example has the |
Thanks for the repros @RobWalker. I think this thread has a lot of useful information already. @Murderlon do you have any sort of ETA for paid customers? I have an open support ticket about this issue. I'm migrating a project to modern frontend tools and this open issue is the only thing preventing us to go forward with our plan. Since Transloadit is a big part of our application, we currently don't have any course of action to pursue while this is still pending. |
@thiagomajesk my current work around is to load uppy from the CDN rather than bundle it via vite, basically add:
to |
@RobWalker I've been considering this, but as you said is not completely ideal for production. Even more so if you are working on applications that can be served in a standalone fashion (eg: on local networks with limited web access and so on). I'll try this while we wait for an official solution 🙃. |
Thanks for the updates. I have been trying to get this to work today but it has been less obvious than I hoped to solve it. I understand this is a timely issue and my goal is to get it released this workweek. |
@thiagomajesk I am afraid that I can't repro this. It's confusing since two projects that shares the same code has difference in success. I'll probably check the CDN work around if that ever solves it temporarily. At least, just to keep everything consistent. |
It was a bit of a confusing process to reproduce this with only |
This now has been fixed! It was fixed in Here is a minimal working example: https://stackblitz.com/edit/vitejs-vite-vgvw5x?file=main.js Reinstall |
Thanks a lot @Murderlon! I'll give it a go as soon as I can. Cheers! |
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
):Creating an simple HTML file and adding a script tag to the head works fine using vite's dev server (
npx vite
):index.html
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).The text was updated successfully, but these errors were encountered: