How to polyfill setImmediate?

Viewed 1533

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?

0 Answers
Related