@uppy/tus: Undocumented dependency on Node’s Buffer API
elliotdickison opened this issue · comments
Initial checklist
- I understand this is a bug report and questions should be posted in the Community Forum
- I searched issues and couldn’t find anything (or linked relevant results below)
Link to runnable example
No response
Steps to reproduce
- Bundle
@uppy/core
and@uppy/tus
in a web app with Vite without polyfilling any Node APIs - Attempt to upload a file with Tus. Note that even though the upload succeeds and no errors are thrown, the
upload-success
event is never fired. - Wrap this line in @uppy/tus with a try/catch and log any errors. Attempt to upload again and note that a
Buffer is not defined
error is thrown.
Expected behavior
I would expect Uppy to document that it requires the Node Buffer
API in the browser. I would also expect it to throw an error in the console if the API is not available.
Actual behavior
Uppy fails silently if the Node Buffer
API is not available.
For anyone trying to get Uppy to work when bundled with Vite, here's the proper thing to do in your vite.config.ts
:
// Install and import this plugin
import { nodePolyfills } from "vite-plugin-node-polyfills"
export default defineConfig({
plugins: [
// The Buffer API appears to be the only one required by Uppy
nodePolyfills({
include: ["buffer"],
globals: { Buffer: true },
}),
]
})
FWIW I tried to follow the logic up the chain from the line where I caught the error to try to figure out what was swallowing it, but I was unable to easily identify the issue.
Do you have a reproducible example on CodeSandbox/StackBlitz? We test against all major bundlers in CI and we use Vite locally to develop and we haven't seen this problem.
My apologies, it must be an issue with a transitive dependency then. Thanks!