3

I use graphql's dataloader in a project. Unfortunately, it breaks Webpack 5 because:

setImmediate is not defined

I see where the issue is coming from in their source code. I forked the repo, made a patch and added it to my package.json. But the file that import dataloader can't resolve the path. So I need to add a polyfill for this function.

I've tried to write this in my file:

if(typeof Window.prototype.setImmediate !== "function") {
  Window.prototype.setImmediate = function() {
    return false
  };
}

But typescript claims that:

Property 'setImmediate' does not exist on type 'Window'

How to fix this?

Mario Petrovic
  • 7,500
  • 14
  • 42
  • 62
DoneDeal0
  • 5,273
  • 13
  • 55
  • 114
  • 1
    See also: [MDN - Window.setImmediate()](https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate) and (there linked) [setImmediate](https://github.com/YuzuJS/setImmediate), and about the bug: [graphql/dataloader - BUG #249](https://github.com/graphql/dataloader/issues/249) – kca Feb 03 '21 at 16:11
  • 2
    Hi, so I've eventually figured it out since I asked the question, and answered to the thread you posted: adding Yuzu's polyfill fixed the issue: https://github.com/YuzuJS/setImmediate/blob/master/setImmediate.js . In case someone has the same issue, just add : import "setimmediate" on top of index.ts/js or at the top of your file(s) that use dataloader, – DoneDeal0 Feb 03 '21 at 16:26

0 Answers0