Angular 8构建不适用于IE,但可以正常运行

时间:2019-10-15 14:43:16

标签: angular internet-explorer

im尝试为ie构建我的angular 8应用程序,但是它不起作用。

我遵循了一些教程和解决方法来“修复”它。
可悲的是,它仅适用于ng serve,不适用于ng buld / ng build --prod

我使用的来源:

  

请注意,这仅适用于开发服务器ng server,不适用于生产版本

现在我不确定问题出在哪里或在哪里进一步解决。

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}

tsconfig.es5.json

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

angular.json

...
build": {
   "builder": "@angular-devkit/build-angular:browser",
      ...
      "configurations": {
         "es5": {
            "tsConfig": "./tsconfig.es5.json"
         },
...
"serve": {
   "builder": "@angular-devkit/build-angular:dev-server",
      ...
      "configurations": {
         "es5": {
            "browserTarget": "my-project:build:es5"
         },

浏览器列表

> 0.5%
last 2 versions
Firefox ESR
not dead
IE 9-11 # For IE 9-11 support, remove 'not'.

对于每个想要a minimal, reproducible example的人,当我刚刚使用Angular Cli 8.3.9和Angular创建一个干净的新项目时:8.2.11就是这样

我在chrome 77和Internet Explorer 11中得到以下输出

  

请注意,当我运行ng server时,它也将在11中运行

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,并且遵循了上述问题中引用的指南。

在IE 11控制台中,我看到以下错误:

SCRIPT1010:预期的标识符 runtime-es5.edb2fcf2778e7bf1d426.js(1,1218)

SCRIPT1010:预期的标识符 polyfills-es5.6696c533341b95a3d617.js(1,10136)

SCRIPT5009:“ JSON”未定义 scripts.6ac48f6315bac860bfde.js(1,18419)

SCRIPT1003:预期为“:” main-es5.4000e45f2a6bbda97c33.js(1,575)

我的环境:

Angular CLI:8.3.18

节点:12.13.0

角度:8.2.13

答案 1 :(得分:1)

我有一个类似的问题。

在我的案例中,IE 11抱怨:

SCRIPT1002: Syntax error in scripts.22d9f1b41174f0698a97.js (1,221172) - pointing to class s{constructor(t,e,n,i)...

好像minifier创建了不兼容的IE JS代码,我的设置是:

浏览器列表:

> 0.5%
last 2 versions
Firefox ESR
dead
IE 9-11 # For IE 9-11 support, remove 'not'.

tsconfig:

"compilerOptions": {
  "downlevelIteration": true,
  "outDir": "./dist/out-tsc",
  "sourceMap": true,
  "declaration": false,
  "moduleResolution": "node",
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true,
  "target": "es5",
  "typeRoots": [
    "node_modules/@types"
  ],
  "lib": [
    "es2018",
    "dom"
  ],
  "module": "esnext",
  "baseUrl": "./"
}

env:

Angular CLI: 8.3.23
Node: 10.9.0
OS: win32 x64
Angular: 8.2.14

我也尝试了目标:2015年(以及差异加载),但它产生了更多错误:/

相关问题