Closed yasirrafiq33 closed 1 year ago
I'm seeing the same error with Vercel edge api functions https://nextjs.org/docs/api-routes/edge-api-routes
Seeing the same issue with background (service worker) scripts in Chrome extensions running on the new manifest V3. Why am I seeing XMLHttpRequest in cross-fetch
?
XMLHttpRequest is not defined
Does anyone resolves it?
Gave up waiting, released my own.
@perry-mitchell , I solved it this way
https://github.com/Tomas2D/pagerduty-calculator/blob/main/src/polyfill.ts https://github.com/Tomas2D/pagerduty-calculator/blob/main/vite.config.ts
@perry-mitchell , I solved it this way
https://github.com/Tomas2D/pagerduty-calculator/blob/main/src/polyfill.ts
https://github.com/Tomas2D/pagerduty-calculator/blob/main/vite.config.ts
But then you're not really using fetch 😅. I needed it in my case as I need to support service workers, which don't provide a working XHR.
You are right, mine is just for NodeJS / Browser environment, not workers. I will use your solution, once I will need to make it work in service workers 👍🏻
Your solution is completely valid of course if the interface of fetch is all that matters. Cheers 👍
I've created a way to disable cross-fetch if you don't need it.
This issue also affects Cloudflare Wrangler
I also have this issue
I've been working on version 4 of cross-fetch
to fix this issue. If anyone's interested, please run npm install cross-fetch@latest-v4.x
in your project and give it a try. Let me know if any issues come up.
Version 4 has been officially released with the fix. Please check it out: npm install cross-fetch
.
This is specific case with nextJs middleware. The package is working fine everywhere but when we try to use it in NEXTJS middleware its throw error. The middleware is using edge runtime. https://nextjs.org/docs/api-reference/edge-runtime