【问题标题】:IE 11 throwing Syntax Error on chunk.js for Angular 7 appIE 11 在 Angular 7 应用程序的 chunk.js 上抛出语法错误
【发布时间】:2021-03-24 08:11:40
【问题描述】:

我们正在构建一个需要支持 IE11 的 Angular 7 应用程序。所以这在我本地开发人员的 IE 框中工作正常。但是,当部署到更高的环境时,它会在 chunk.js 上给出一个语法错误,因为哪个应用程序没有呈现:

SCRIPT1002: Syntax Error
0.f7d1b3144b6e689b2f6b.chunk.js (1,1088655)

这在包括 EDGE 在内的所有其他浏览器中都可以正常工作。 我不知道如何调试/理解这个错误。任何帮助,将不胜感激。 我添加了以下 polyfill:

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/es7/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`.

/** Evergreen browsers require these. **/
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';

/**
 * Required to support Web Animations `@angular/animation`.
 * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
 **/
import 'web-animations-js';  // Run `npm install --save web-animations-js`.

/***************************************************************************************************
 * Zone JS is required by Angular itself.
 */
import 'zone.js/dist/zone'; // Included with Angular CLI.

tsconfig-aot.json:

{
    "compilerOptions": {
        "target": "es5",
        "module": "es2015",
        "moduleResolution": "node",
        "sourceMap": false,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false,
        "suppressImplicitAnyIndexErrors": true,
        "skipLibCheck": true,
        "outDir": "target/www/app",
        "lib": ["es7", "dom"],
        "typeRoots": [
            "node_modules/@types"
        ],
        "baseUrl": "./",
        "paths": {
            "app/*": ["src/main/webapp/app/*"]
        },
        "importHelpers": true
    },
    "angularCompilerOptions": {
        "genDir": "target/aot",
        "skipMetadataEmit" : true,
        "fullTemplateTypeCheck": true,
        "preserveWhitespaces": true
    }
}

tsconfig.json

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false,
        "skipLibCheck": true,
        "suppressImplicitAnyIndexErrors": true,
        "outDir": "target/classes/static/app",
        "lib": ["es7", "dom"],
        "typeRoots": [
            "node_modules/@types"
        ],
        "baseUrl": "./",
        "paths": {
            "app/*": ["src/main/webapp/app/*"]
        },
        "importHelpers": true,
        "allowJs": true
    },
  "include": [
    "src/main/webapp/app",
    "src/test/javascript/"
  ],
    "exclude": [
        "node_modules"
    ]
}

【问题讨论】:

  • 除了添加polyfill,你有没有运行npm install --save classlist.js等安装包?请参考this answer 以确保您已按照步骤在 IE 11 中支持 Angular 7。我记得 Angular 7 不需要修改 tsconfig.json 即可支持 IE 11。此外,请比较本地环境和更高环境之间的差异,看看是否存在一些差异会导致问题。

标签: angular internet-explorer angular7


【解决方案1】:

您的源代码中有一个class 关键字,IE11(仅支持 ES5)不支持它。您需要更改target 属性哟es5

您可以像这样添加tsconfig-es5.app.json 文件:

{
    "extends": "./tsconfig-aot.json",
    "compilerOptions": {
        "target": "es5" 
    }
}

然后在你的 angular.json 文件中,添加一个es5 配置目标:

"configurations": {
    "es5" : {
                  "tsConfig": "./tsconfig-es5.app.json"
                }
}

那么,你应该可以运行了:npm run build --configuration=es5

【讨论】:

  • 对不起,我忘了补充一点,该应用程序在本地开发人员的框中运行良好。只有当我们将它们部署在 ICP 的更高环境中时,这才会失败。我在问题中也添加了 tsconfig.json 。所以我已经指定了目标:“es5”。仍然需要您的解决方案吗?以及代码如何在本地机器上运行但在更高的环境中失败。在 ICP 上部署。
  • 如果您有许多 tsconfig.json 文件(tsconfig.json、tsconfig-app.json、tsconfig-aot.json 等),这是可能的。也许其中一个已被使用并且没有es5 目标
  • 我们有 tsconfig.json 和 tsconfig-app.json,我已经在问题中发布了这两个。他们都有 es5 目标
猜你喜欢
  • 2020-06-05
  • 1970-01-01
  • 2018-11-08
  • 2019-01-01
  • 2014-06-12
  • 2021-10-25
  • 2018-12-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多