Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Object.entries is not a function

On mdn docs, there is a clear tutorial on Object.entries, and it is described what to be done if Object.entries is not supported on part PolyFill in the same page.

To add compatible Object.entries support in older environments that do not natively support it, you can find a demonstrational implementation of Object.entries in the tc39/proposal-object-values-entries (if you don't need any support for IE), a polyfill in the es-shims/Object.entries repositories, or you can use the simple, ready to deploy polyfill listed below.

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;
   };

According to http://kangax.github.io/compat-table/es2016plus/ under the Object static methods, it seems you need to enable the harmony flag

So run node like this

node --harmony script.js

you could use babel-polyfill for quick solution

npm install babel-polyfill

import 'babel-polyfill';

In case this helps someone else...

Update your version of Node. I was running node 6.x and this issue resolved itself after I updated to node 8.x+


First install react-app-polyfill:

npm install react-app-polyfill

Then import to the top of your index.jsx before import React:

import 'react-app-polyfill/stable';