Typeerror: Object. Entries Is Not a Function

Why do I keep getting this error when trying to run my server?

Is this a part of the newer ES7? What do I need to be able to run an app using these new features?

6

7 Answers

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

According to under the Object static methods, it seems you need to enable the harmony flag

So run node like this

node --harmony script.js
3

you could use babel-polyfill for quick solution

npm install babel-polyfill

import 'babel-polyfill';
1

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+

2

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

In my case it resolved itself when I switched from node 11.15.0 to lts/erbium / 12.18.3.

Instead of

const myObj = {a: 1, b: 2}

myObj.entries()

do

Object.entries(myObj)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest