tus / tus-js-client

A pure JavaScript client for the tus resumable upload protocol
https://tus.io/
MIT License
2.09k stars 314 forks source link

tus-js-client failing to run in Cloudflare Workers #388

Open Schachte opened 2 years ago

Schachte commented 2 years ago

Describe the bug I'm attempting to leverage tus for large file uploads using Cloudflare Workers. Simply running const tus = require("tus-js-client") yields window is not defined.

I've tried various hacks like defining window in global scope to an empty object, trying conditional importing, but I can't seem to get around this. Any suggestions?

import * as tus from "tus-js-client"; 
const tus = require("tus-js-client"); 

These yield the same result

Acconut commented 2 years ago

I have never used Cloudflare Workers, so my knowledge is limited. However, it seems that they implement a limited set of browser-like APIs (such as WebSocket, Web Crypto, Fetch etc) but not a full browser environment. Hence window is not defined.

So it seems as if tus-js-client is currently not compatible with Cloudflare Workers, but I think it would be possible to achieve support for that. Two things need to be changed at least:

All in all, tus-js-client could run on Workers. Let me know if you are interested in helping with the above points. I don't have enough time to work on them on my own, but I am more than willing to assist you.

Schachte commented 2 years ago

Hey @Acconut , apologies for the late response. Thanks for the detailed reply! Once I get a bit of time, I can circle back to this and try and throw up a PR. 

Acconut commented 2 years ago

@Schachte Great to hear back from you! Let me know if you need further assistance!

JudahMantell commented 1 month ago

Has there been any work on this since?

Acconut commented 1 month ago

There has been no further progress since. Would you be interested in submitting a PR for this?