Search code examples
typescriptwebpackpolyfills

Using Set polyfill in webpack doesn't resolve errors


I'm seeing some "Can't find variable: Set" errors in production on older browsers. I figure this is Typescript and Webpack being ambitious about their usage of es6 features, no big deal, I can polyfill that just like I've polyfilled Object.assign for React.

Now my Polyfill config for webpack looks like this:

// using include in the callback selection requires a polyfill for ie
require('string.prototype.includes');

// some older browsers don't support Set, which apparently something compiles to
require('es6-set');

// fetch() polyfill for making API calls.
require('whatwg-fetch');

// Object.assign() is commonly used with React.
// It will use the native implementation if it's present and isn't buggy.
Object.assign = require('object-assign');

But after releasing and verifying the release is out, I'm still seeing errors in older browsers relating to Set. I've looked through the docs for adding polyfills to webpack and I don't see if I'm missing a step or why this isn't working.

What am I doing wrong, or what else can I try?


Solution

  • Your code:

    // some older browsers don't support Set, which apparently something compiles to
    require('es6-set');
    

    Does not follow the readme of the project : https://www.npmjs.com/package/es6-set

    Fix

    From the readme :

    require('es6-set/implement');