0

I am trying to load my web application on IE11 with the following browserslist configuration in package.json

"browserslist": {
 "production": [
   ">0.2%",
   "not dead",
   "not op_mini all"
 ],
 "development": [
   ">0.1%",
   "not dead",
   "not op_mini all"
 ]
}

and with the following statements at the beginning of src/index.tsx

import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';

But I get an error saying SCRIPT438: Object doesn't support property or method 'entries'. To overcome this I read the SO post at Object doesn't support property or method 'entries' but no good.

I tried installing yarn add core-js but when I try to do import 'core-js/es7/object'; the build fails saying the module does not exist. What should I do here? What is it that I am missing?

Amanda
  • 2,013
  • 3
  • 24
  • 57
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/210837/discussion-on-question-by-amanda-getting-object-doesnt-support-property-or-meth). – Samuel Liew Apr 03 '20 at 01:25

1 Answers1

1

I tried installing yarn add core-js but when I try to do import 'core-js/es7/object'; the build fails saying the module does not exist. What should I do here? What is it that I am missing?

Perhaps the issue is related to the core-js version. In my react application, it using core-js@3.0.1 version, it doesn't contain the es7 folder, and if I using the Object.entries() method, it works well in IE11 (not add polyfill, perhaps it already add the object reference).

enter image description here

Besides, I also checked my another application, it using the core-js 2.6.1 version, and we can see the core-js folder contain es7 package, you could also check the core-js version:

enter image description here

Try to refer this link to update core-js version:

Besides, you could also add the following script in the header of Index.html. It also works well in IE11 browser.

    <script>
    if (!Object.entries) {
      Object.entries = function( obj ){
        var ownProps = Object.keys( obj ),
            i = ownProps.length,
            resArray = new Array(i); // preallocate the Array
        while (i--)
          resArray[i] = [ownProps[i], obj[ownProps[i]]];

        return resArray;
      };
    }
    </script>
Zhi Lv
  • 18,845
  • 1
  • 19
  • 30
  • I added `import "core-js/es/object";` at the top of `index.tsx` but still see the error. I am at `"core-js": "^3.6.4",` – Amanda Apr 07 '20 at 07:20
  • How about the second method (add the JavaScript script in the header of Index.html), whether it works? – Zhi Lv Apr 07 '20 at 10:03