Using Object.assign() in Internet Explorer 11 while working with Angular 2

Despite the countless discussions on this issue, I have not found a solution that works for me.

This is the current content of my polyfills.browser.ts file:

import 'ie-shim';
import 'core-js/es7/reflect';

import 'reflect-metadata';
import 'zone.js/dist/zone';

I have tried various methods to resolve this problem.

Firstly, I attempted adding all default uncommented imports:

import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/set';

Additionally, I experimented with:

import "core-js/client/shim";

and also tried:

import 'mdn-polyfills/Object.assign';

as well as

import 'core-js';

All these imports were added at the beginning of polyfills.browser.ts

Unfortunately, none of them resolved the issue and I continue to encounter the error message stating Object doesn't support property or method 'assign' in IE11.

Answer №1

Object.assign was introduced in ES2015 and can be implemented using a polyfill:

import 'core-js/es6/object';

For a wider coverage of ES2015 polyfills, you can use:

import 'core-js/es6';

The reason why it's recommended to specify ES2015 polyfills in an Angular application instead of just importing core-js/es6 is that the core-js/es6/promise polyfill is already included in Zone.js and could potentially cause issues.

If you encounter an

Object doesn't support property or method 'assign'

error message, it indicates that the polyfills bundle wasn't loaded in the browser, or the piece of code containing Object.assign was executed before the polyfills bundle finished loading.

Answer №2

I encountered a similar issue while using a polyfill on IE11, although not consistently. The problem occurred when the main script was loaded before the polyfills sometimes. To address this, I made a modification to the webpack configuration:

       new CommonsChunkPlugin({
-        name: 'polyfills',
-        chunks: ['polyfills']
+        name: ['polyfills', 'main'].reverse(),
       })

By making this change, now simply:

new CommonsChunkPlugin({
  name: ['polyfills', 'main'].reverse(),
})

it appears to be functioning correctly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Combining data using D3's bar grouping feature

I'm currently exploring ways to group 2 bars together with some spacing between them using D3. Is there a method to achieve this within D3? I found inspiration from this example. var data = [4, 8, 15, 16, 23, 42]; var x = d3.scale.linear() .doma ...

Creating distinct web addresses for various sections of vue.js pagination

I've implemented pagination using vue.js for my website's gallery. However, I'm facing an issue where the URL doesn't change when navigating through pages and upon page refresh, it always resets to page 1. My goal is to have the URL ref ...

"Step-by-step guide on associating JSON data with <li> elements using AngularJS

Currently, I am working on creating an application using AngularJS that involves retrieving data from a database and populating a list item with that data. To achieve this, I have written a WebMethod as shown below: [WebMethod] public static string g ...

Experience interactive 3D model viewer in action

I want to embed this 3D model viewer into an existing div instead of creating a new one. I've made some edits to the code but it's not working. Any assistance would be greatly appreciated. <script> // Here is where the model viewer cod ...

Utilizing AngularJS: Employing the $q Promise Feature to Await Data Readiness in this Scenario

I am currently facing an issue with my Controller and Factory. The Controller initiates an API call in the Factory, but I am struggling to make it wait for the data to be gathered before proceeding. This is where I believe implementing something like $q mi ...

Why won't setInterval function properly with innerHTML?

I've been attempting to include a small feature on my website that displays the running seconds, but for some reason my JavaScript function isn't working. Strangely, it's not throwing any errors either. Here's the code I'm using: f ...

Tips on adjusting the width of columns in a Google chart?

Is there a way to adjust the width of the bars in a Google chart column? I attempted to set 'bar: { groupWidth: "20%" }' but it had no effect on the chart. https://i.sstatic.net/jM3o0.png I really want to make the bars thinner. Below ...

p-menu fails to appear

I'm currently experimenting with Primeng and Angular 2 to put together a basic menu. Take a look at my code snippet: import {Component, OnInit} from '@angular/core'; import {Menu, MenuItem} from 'primeng/primeng'; @Component({ ...

Using CSS on a randomly selected div that is chosen after dividing the main div each time it is clicked

Imagine a square box displayed as a "div" element. When you click on it, it splits into an n x n grid with each square having a random background color. However, the issue I am encountering is that I want to apply additional CSS to each of these randomly c ...

Creating Angular Components Dynamically through API Requests

Generating Component Template and Typescript Code Dynamically I am attempting to dynamically create a component where an HTTP service call provides us with the HTML template and Typescript code. While we can set the HTML template dynamically, I am facing ...

Full width divider for Ionic 2 lists

I am currently facing an issue with my Ionic 2 app where the divider is only full width on the last element in the list. I would like all elements to have a full width border, but I couldn't find any information about this in the documentation. Any he ...

Is there a Node template engine similar to EJS that seamlessly integrates with HTML templates?

Is there a template engine for NodeJS similar to EJS that doesn't alter the original HTML template structure with its use of parentheses? In EJS, one might utilize the following code snippet to embed specific data into the HTML template: <script& ...

Conceal the HTML input element until the JavaScript has finished loading

Currently, I am using a JQuery plugin to style a form input with type 'file'. The plugin adds a new span over the input element to create a mask effect and encloses everything in a div. However, there is an issue where the standard HTML input box ...

What is the proper way to incorporate an if statement within a new instance?

After creating a new instance, I am looking to disable the pagination based on the variable enablePagination = false. However, I am unsure of how to set the if condition within that instance. If the condition is true, then it should be operational. var ...

In search of a new object value to update

Looking to update the value of a specific object key in an array? Here is the code snippet where I want to make this change. I only want to replace the value under Mon, not the entire array length. The key weekday will be provided dynamically. array = [ ...

What could be causing IdentityServer 4 code flow to intermittently receive an invalid_grant response?

For my Angular application, I have implemented the identityserver4 code flow using the angular-oauth2-oidc library. Here is a snippet of my configuration: OauthConfig: AuthConfig = { issuer: 'http://mydomain.identityserver4', ...

Trouble with populating Ext.grid.Panel from ExtJS4 JSON data

Despite researching various posts on the topic, I am still facing issues. Even after attempting to create a Panel with minimal data, I cannot seem to make it work. This problem is really puzzling me. Below is the code snippet that I am currently working wi ...

jquery has a strange behavior where the dialog window will cover up the scrollbar when the main

Currently, I am utilizing jQuery dialog to display a dialog window. I have managed to position it at the bottom left corner as desired. However, when the main window contains a scrollbar, the dialog ends up overlapping with the scrollbar instead of alignin ...

What is the best way to use a JavaScript function as a callback?

I'm struggling with understanding callbacks, especially how they function. Here is my function: function checkDuplicateIndex(values, callback) { $.ajax({ type: "POST", url: url, data: "command=checkIndexAlbumTracks& ...

The `react-hover` npm package functions flawlessly in the development environment despite being excluded from the production build

While working on my project, I decided to utilize the npm package react-hover and it's been effective during local development in dev build. However, when I execute the npm run build command to serve the production version, the components within the & ...