Angular 2+: Internet Explorer: Unable to get prope

2019-07-03 19:20发布

问题:

In Angular 4.2.4 (Angular-CLI 1.1.3), IE11 I get SCRIPT1002: Syntax error and SCRIPT5007: Unable to get property 'call' of undefined or null reference. I have my polyfills in and I would have assumed that Webpack and Angular-CLI would have done the rest. What am I missing here?

Unable to get property 'call' of undefined or null reference says after it: bootstrap 50034e0a1f93dabcb117 (54, 1) with no indication of a real filename. And Syntax error says it's in vendor.bundle.js (63117,26), which looks like:

window.setTimeout(() => {
    window.removeEventListener('click', suppressClick, true);
}, 0);

Update: Should have been more obvious to me before, but this looks like ES6 code, and it should be compiling down to ES5.

回答1:

There could be a lot of problems here as mentioned in the comments but I recently had a problem with browser compatibility and the solution was to use polyfills. Uncomment the following lines:

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
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/weak-map';
import 'core-js/es6/set';

And run your application. It should be working down to IE10 at least it worked out for us. Based on the error message it is likely to work for You as well.



回答2:

Try to load jQuery polyfills from assets:

in index.html's head:

  <script src="assets/...">

My take is to try at least https://plugins.jquery.com/webshims/



回答3:

For anyone still running into this issue, try this:

Angular 2+: IE 11 Unable to get property 'call' of undefined or null reference

If the error you're getting occurs on a hunk of code that looks like this:

window.setTimeout(() => {
    window.removeEventListener('click', suppressClick, true);
}, 0);

...then please let me know if the solution worked or not. I will update this answer, and possibly mark this question as duplicate.

I DO NOT BELIEVE THESE TO BE THE SAME ISSUE AT THIS TIME, AS THE ERRORS OCCURRED ON DIFFERENT CODE IN bundle.js. Someone voted this answer down, without giving any feedback on whether or not these questions have the same solution.

I do not have a way to test this currently, but wanted to direct folks to a possible solution.