【发布时间】:2019-06-06 13:16:11
【问题描述】:
我正在创建一个新应用程序,我的目标浏览器是 IE11。当我将目标用作 es6 时,我的应用无法加载并显示如下所示的错误。
但是当我将目标更改为 es5 时,一切似乎都正常。我的疑问是,添加 polyfill 是为了确保旧版浏览器支持较新的 JavaScript 函数。我已经启用了所有针对 es6 的 polyfill,如下所示
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
*/
/***************************************************************************************************
* BROWSER POLYFILLS
*/
/** 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';
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
import 'classlist.js'; // Run `npm install --save classlist.js`.
/** IE10 and IE11 requires the following for the Reflect API. */
import 'core-js/es6/reflect';
/** Evergreen browsers require these. **/
// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
import 'core-js/es7/reflect';
/**
* Web Animations `@angular/platform-browser/animations`
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
**/
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
/**
* By default, zone.js will patch all possible macroTask and DomEvents
* user can disable parts of macroTask/DomEvents patch by setting following flags
*/
// (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
// (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
// (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
/*
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
* with the following flag, it will bypass `zone.js` patch for IE/Edge
*/
// (window as any).__Zone_enable_cross_context_check = true;
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS
*/
我的问题是,即使所有针对 es6 的 polyfill 都已导入,为什么我的应用程序不来?我在这里错过了什么吗?请帮忙。
对建议重复的回应
我相信这不是this question 的重复。我有解决方案(将 ES6 更改为 ES5)。但是该问题的答案并没有说明为什么即使添加了 polyfill 也不支持 ES6。我相信这个问题与预期的答案完全不同。
【问题讨论】:
-
为什么不是您提到的问题的重复,我有解决方案(将es6更改为es5)。但是您提到的问题的答案并没有说明原因,即使添加了 polyfill,es6 也不支持。我相信这个问题与预期的答案完全不同。如果您能在将其标记为重复之前阅读并分析问题,那就太好了。
-
那么您在
vendor.js (140, 1)和main.js (39, 1)中找到了什么代码?可能是class或arrow function,即一些 ES6 语法特性。 Polyfills 不会将 ES6 代码转换为 ES5。 stackoverflow.com/q/31205640/9423231 -
您使用的是哪个版本的 Angular?