isaacs / node-lru-cache

A fast cache that automatically deletes the least recently used items
http://isaacs.github.io/node-lru-cache/
ISC License
5.38k stars 353 forks source link

Collision with abort-controller #255

Closed omer727 closed 2 years ago

omer727 commented 2 years ago

This library cause me collision with 'node-fetch' and 'abort-controller'. How to reproduce:

  1. just import 'lru-cache';
  2. import 'node-fetch' and 'abort-controller':
  3. The following code will throw new TypeError('Expected signal to be an instanceof AbortSignal')
    const controller: AbortController = new AbortController();
    const timeoutId = setTimeout(() => controller.abort(), 10 * 1000); //10 seconds timeout
    const fetchParams: RequestInit = {
        headers: {},
        method: 'GET',
        signal: controller.signal,
    };
    await fetch('http://github.com/', fetchParams); //do the actual http request

It's because

isaacs commented 2 years ago

Oh, the battle of the polyfills, I'm sorry.

You can work around it for now by changing the import order, or pulling in a specific global AC polyfill initially, but yes, this is annoying. I'm not sure the best way around it, since both libraries are trying to polyfill the same missing global.

isaacs commented 2 years ago

When support for v14 and earlier drops, we can remove this polyfill. Until then, we're stuck with workarounds. Load node-fetch first, or update node to v18 and use its built-in fetch implementation.