目标为es6

时间:2019-06-06 13:16:11

标签: angular angular6

我正在创建一个新的应用程序,并且我的目标浏览器是IE11。当我将目标用作es6时,我的应用程序无法加载并显示错误,如下所示。

syntax errors

但是当我将目标更改为es5时,一切似乎都可以正常工作。我的疑问是,添加了polyfills以确保旧版浏览器支持较新的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的polyfills都已导入,为什么我的应用程序不发布?我在这里想念什么吗?请帮忙。

对建议的副本进行回复

我相信这不是this question的副本。我有解决方案(将ES6更改为ES5)。但是,该问题的答案并未说明为什么即使添加了polyfill也不支持ES6。我认为问题完全不同,答案也有所不同。

2 个答案:

答案 0 :(得分:3)

如Angular文档所述:Differential loading is currently only supported when using es2015 as a compilation target. When used with targets higher than es2015, a warning is emitted during build time. https://v8.angular.io/guide/deployment#differential-loading

这只是意味着在tsconfig中,您必须使用"target": "es2015",

您还必须确保正确配置browserslist(或package.json)文件。可能您想添加zone-flags.ts。

最后,如果您使用Object.values之类的东西,还必须import 'core-js/es7/object';进入您的polyfills文件,当然,如果您还使用其他东西,还必须cd Desktop/RNStoreLocatorExample 进入。

答案 1 :(得分:0)

您的应用程序无法正常运行,因为IE11不支持大多数ES6功能。您必须在ES5中定位您的应用。

您可以在此处查看ES6对IE11的支持:ECMA compatibilty

相关问题