angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Object.entries not supported in IE

Open ylligashi opened this issue 8 years ago • 9 comments

Object.entries should be included in the polyfills for IE support

Versions

Angular CLI: 1.5.0 Node: 8.9.1 OS: darwin x64 Angular: 5.0.3 ... animations, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, router

@angular/cli: 1.5.0 @angular-devkit/build-optimizer: 0.0.33 @angular-devkit/core: 0.0.21 @angular-devkit/schematics: 0.0.37 @ngtools/json-schema: 1.1.0 @ngtools/webpack: 1.8.0 @schematics/angular: 0.1.7 typescript: 2.4.2 webpack: 3.8.1

Repro steps

If you ever want to use Object.entries you can not

Observed behavior

Object.entries is not supported in IE

Desired behavior

Object.entries should be supported and added to polyfills

Mention any other details that might be useful (optional)

This is the code to be added:

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

Source: https://stackoverflow.com/questions/42446062/object-doesnt-support-property-or-method-entries

ylligashi avatar Mar 13 '18 14:03 ylligashi

I believe this is handled by the polyfills defined in the polyfills file. You'll have to uncomment those for IE support in that file. If that does not solve you issue, you could add the definition you have above into that file yourself.

Brocco avatar Mar 13 '18 16:03 Brocco

@Brocco I did uncomment the polyfills but still needs a polyfill for Object.entries to be added.

ylligashi avatar Mar 13 '18 16:03 ylligashi

Object.entries comes from ES7 =>

import 'core-js/es7/object';

wKoza avatar Mar 14 '18 07:03 wKoza

@wKoza thanks, I also think that this should be added to the polyfills list on: /** IE9, IE10 and IE11 requires all of the following polyfills. **/

ylligashi avatar Mar 14 '18 14:03 ylligashi

Only polyfills required by Angular itself are included in the list. If an application's code needs specific polyfills then they can be added as needed.

clydin avatar Mar 14 '18 23:03 clydin

Closing as answer in the above comment.

alan-agius4 avatar Mar 13 '19 10:03 alan-agius4

Only polyfills required by Angular itself are included in the list. If an application's code needs specific polyfills then they can be added as needed.

But how can we make those polyfills to be added to es2015-polyfills.js? If those are added to the general polyfills.js it kinda defeats the purpose.

PierreDuc avatar Apr 03 '19 07:04 PierreDuc

Have solved by adding this to polyfills.js

// Integra addition
// IE 11 needs Object.entries, but that's not covered by Angular / webpack es2015-polyfills.js
import 'core-js/es7/object';

chris-denning avatar May 26 '19 09:05 chris-denning

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.