"XMLHttpRequest is not defined" on sveltekit endpoints when deployed on Vercel
See original GitHub issueBug report
Describe the bug
Using the client for auth or for querying the database in a sveltekit endpoint throw an error :
{
data: null,
error: ReferenceError: XMLHttpRequest is not defined
at file:///var/task/server/app.mjs:2522:21
at new Promise (<anonymous>)
at fetch2 (file:///var/task/server/app.mjs:2517:16)
at file:///var/task/server/app.mjs:2646:7
at new Promise (<anonymous>)
at file:///var/task/server/app.mjs:2645:12
at Generator.next (<anonymous>)
at file:///var/task/server/app.mjs:2619:67
at new Promise (<anonymous>)
at __awaiter$8 (file:///var/task/server/app.mjs:2601:10)
}
To Reproduce
I made a repository exposing the issue : https://github.com/Pixselve/supabase-sveltekit-endpoints Click on a button to fetch the endpoint and observe the cloud functions logs on Vercel.
Expected behavior
Requests should not fail and should give the appropriate data.
System information
- OS: Vercel Node.js Runtime
- Version of supabase-js: 1.10.0
- Version of Node.js: 14
Issue Analytics
- State:
- Created 2 years ago
- Comments:27 (9 by maintainers)
Top Results From Across the Web
XMLHttpRequest is not defined in frontend code
I am using svelte, and all the questions about this error are about backend node.js code. javascript · html · typescript · frontend...
Read more >Endpoints – Vercel Docs
In this module, we will learn how to create server-side routes using SvelteKit endpoints.
Read more >Make a Simple API Endpoint with Vercel Serverless Functions
Deploy to Vercel. Righty ho! Time to deploy to Vercel! The script is already in the project when I defined the start and...
Read more >Deploying SvelteKit App to Vercel : r/sveltejs - Reddit
Test run the setup by running npm run build , this should create a .vercel_build_output folder and produce no errors. Push your app...
Read more >Profile for Netlify - Linknovate
Let's look at what we've learned: How to set up SvelteKit and create ... Benefits: Quick deployment Secure (no dynamic content) Fast load...
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
After running
npm update
to update packages and re-deploying, it now works as expected in production on Cloudflare Pages! (usingfetch: (...args) => fetch(...args)
, didn’t try the other syntaxes yet.). Thank you SO MUCH @jacobwgillespie ! I can’t thank you enough!Thanks to a very impressive series of PRs from @jacobwgillespie , this now has a workaround
https://github.com/supabase/supabase-js/releases/tag/v1.27.0
after upgrading to v1.27.0 you can use a custom
fetch
implementationJacob - if you send your details (and tshirt size) to swag@supabase.io we will send you a nice package 🙏