Search code examples
javascriptfetch-apipolyfills

Polyfill for TextDecoder


I'm using fetch and have included the whatwg-fetch polyfill in my application.

I also employ TextDecoder as described in Jake Archibald's blog That's so fetch! to decode the response, but I'm not sure what polyfill to use.

(Currently Safari complains about ReferenceError: Can't find variable: TextDecoder)

I'm guessing there's a polyfill for TextDecoder, but I'm not finding it...


Solution

  • I was able to solve this problem by using the text-encoding library

    npm install text-encoding --save
    

    along with

    import encoding from 'text-encoding';
    const decoder = new encoding.TextDecoder();