Why do I keep getting this error when trying to run my Node.js/Express server?
Is this a part of the newer ES7? What do I need to be able to run an app using these new features?
Why do I keep getting this error when trying to run my Node.js/Express server?
Is this a part of the newer ES7? What do I need to be able to run an app using these new features?
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
--latest
or similar. One less character to type as well. ;-) –
Annalee 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+
you could use babel-polyfill
for quick solution
npm install babel-polyfill
import 'babel-polyfill';
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';
Instead of
const myObj = {a: 1, b: 2}
myObj.entries()
do
Object.entries(myObj)
In my case it resolved itself when I switched from node 11.15.0
to lts/erbium
/ 12.18.3
.
© 2022 - 2024 — McMap. All rights reserved.