Search code examples
javascriptcookiesinternet-explorer-11js-cookie

IE11/Windows 10 => Object doesn't support property or method 'includes'


In IE11 on Windows 10, I'm getting Object doesn't support property or method 'includes' error on Cookie.set('something', null). Previously I had Cookie.remove('something') and that was giving the same error.

  Cookie = require('js-cookie')
  Cookies.set('save_lead', null)
  // used to be:
  // Cookies.remove('save_lead')

enter image description here enter image description here


Solution

  • I found solution to this using the array-includes npm package. At first glance it looks like it just gives you a replacement for calling arr.includes('foo') but it also allows for a shim.

    From github README:

    var includes = require('array-includes');
    var assert = require('assert');
    /* when Array#includes is not present */
    delete Array.prototype.includes;
    var shimmedIncludes = includes.shim();
    
    assert.equal(shimmedIncludes, includes.getPolyfill());
    assert.deepEqual(arr.includes('foo', 1), includes(arr, 'foo', 1));
    

    Hope it helps others.