question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not working on cloudflare worker

See original GitHub issue

Hi,

Cloudflare worker provides a fetch function, however, when I’m webpacking your lib, it does seem to use XMLHttpRequest

ReferenceError: XMLHttpRequest is not defined

I did try to force webpack to use node

module.exports = {
  target: "webworker",
  entry: "./worker.js", // inferred from "main" in package.json
  resolve: {
    mainFields: ['module', 'main']
  }
};

But it generates another error (global not defined)

Is there a way to force cross-fetch to to use the native fetch function?

as a proof of concept/fugly workaround, I replaced

const Fetch = fetch; //require('cross-fetch');

and it seems to work fine.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:9
  • Comments:8

github_iconTop GitHub Comments

1reaction
joshmsamuelscommented, Mar 2, 2022

The link is 404’ing since the dist folder that I was referencing was deleted along with all the other dist files at the beginning of the year.

It looks like that was also how browser fetch was supported so I am unsure what @lquixada’s plan was as the owner and maintainer of the repo.

1reaction
joshmsamuelscommented, Oct 3, 2021

👀 https://github.com/lquixada/cross-fetch/blob/main/dist/browser-ponyfill.js#L546

Uncommenting that line and commenting out the one below fixed my issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Worker not running - Cloudflare Community
I have created a worker for my website but it is not working in all cases. The DNS I have set contains 2...
Read more >
Known issues · Cloudflare Workers docs
Known issues. Below are some known bugs and issues to be aware of when using Cloudflare Workers. ​​ Route specificity.
Read more >
Worker not working when enabled for a specific route
My worker should retrieve content from a different page and it's not doing it. It means the routes I set are not working....
Read more >
Worker route not working - Cloudflare Community
Hello! I have a problem with Worker, namely I want to add response header for specific domains, I configured such routes: *example.com/*, ...
Read more >
Routes not working for worker - Cloudflare Community
Hi, I have deployed two workers with routes and query parameters in the URL through the wrangler GitHub Action. One has been successful...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found