Polyfill for TextDecoder

sfletche picture sfletche · Nov 17, 2016 · Viewed 12.3k times · Source

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...

Answer

sfletche picture sfletche · Nov 17, 2016

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();