Support Cloudflare pages/workers
See original GitHub issueI have a project that’s deployed to Cloudflare. The runtime environment behaves like a service worker, so it has fetch
but not window
, hence getting this error:
ReferenceError: window is not defined
at node_modules/isomorphic-form-data/lib/browser.js
There’s a PR to fix isomorphic-form-data, I doubt it’s getting merged: https://github.com/form-data/isomorphic-form-data/pull/6
There’s also no XHR (some specific technical reasons for that), so importing masto/fetch
also fails:
TypeError: globalThis.XMLHttpRequest is not a constructor
at node_modules/rollup-plugin-node-polyfills/polyfills/http-lib/capability.js
I wonder if there’s an easy fix here, maybe a bundle that doesn’t use any polyfills?
Issue Analytics
- State:
- Created 9 months ago
- Comments:12 (11 by maintainers)
Top Results From Across the Web
Cloudflare Pages
Build fast sites. In record time. Cloudflare Pages is a JAMstack platform for frontend developers to collaborate and deploy websites. Sign Up.
Read more >Cloudflare Pages Goes Full Stack
Welcome to the future, everyone. We're thrilled to announce that Pages is now a Full Stack platform with help from Cloudflare Workers!
Read more >Functions · Cloudflare Pages docs
With Pages, you can now build full-stack applications by executing code on the Cloudflare network with help from Cloudflare Workers Open ...
Read more >Migrating from Workers Sites to Pages - Cloudflare Docs
You can migrate your redirects to Pages, by creating a _redirects file in your output directory. Pages currently offers limited support for ...
Read more >Cloudflare Workers®
Build your next application with Cloudflare Workers. ... within milliseconds of your users worldwide; Say goodbye to cold starts—support for 0ms worldwide.
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
Thank you for explaining. I thought it was about FromData, but now I understand it is Mastodon’s undocumented behaviour. I don’t know it if is intended, but as you described, setting Content-Type to multipart/form-data doesn’t seem to make sense.
I made a PR that removes Content-Type when the body is an instance of FormData regardless if it’s containing a Blob #758. It will be released soon
Essentially they’re running server-side code in V8 as service workers. A service worker can listen and respond to HTTP requests as fetch events: https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent
Service workers don’t have access to
window
, the global context isglobalThis
, which also exists in Node.I get the same error using Masto from a Chrome extension, it runs code in the background like a service worker. But Chrome is fine with
masto/fetch
, I’m guessing the XHR issue is specific to Cloudflare so they throttle outbound requests.