【问题标题】:Angular 8 + IE 11 angular application not working on IE 11Angular 8 + IE 11 Angular 应用程序无法在 IE 11 上运行
【发布时间】:2020-06-05 00:08:36
【问题描述】:

我正在研究 Angular 8。我的应用程序已准备好投入生产,但它不适用于 IE11。所有其他浏览器都可以正常工作。在 IE 11 上,它会出现一个带有一些错误的空白页面。我已经通过一些网站做了以下。仍然无法正常工作:(。提前感谢您的帮助

第 1 步:

...
"target": "es5"

第 2 步: 不是 IE 9-10 IE 11

第 3 步 更改 polyfil.ts

“仍然没有任何效果”

【问题讨论】:

  • 你添加了polyfils吗?见https://angular.io/guide/browser-support
  • 你得到什么样的错误?
  • 嘿,假设这是一个有角度的 CLI 应用程序是否安全?

标签: arrays angular internet-explorer build production


【解决方案1】:

我会建议你开始使用 IE 进行调试。转到引发错误的单个文件。 大多数情况下,使用

会引发错误

=>

许多其他人都可以。因此,您需要将这些代码转换为更基本的代码。我用于转译代码的转到站点是:Babel。只需要将这些代码更改为转译代码即可。

希望对你有帮助。

【讨论】:

    【解决方案2】:

    您需要按照以下步骤使 Angular 8 应用程序在 IE 11 中运行:

    1. tsconfig.app.json 旁边创建一个新的tsconfig tsconfig-es5.app.json,内容如下:

      {
       "extends": "./tsconfig.app.json",
       "compilerOptions": {
           "target": "es5" 
        }
      }
      
    2. angular.jsonbuildserve 目标下添加两个新的配置部分以提供新的tsconfig:

      "build": {
        "builder": "@angular-devkit/build-angular:browser",
        "options": {
            ...
        },
        "configurations": {
          "production": {
              ...
          },
          "es5": {
            "tsConfig": "./tsconfig-es5.app.json"
          }
        }
      },
      "serve": {
        "builder": "@angular-devkit/build-angular:dev-server",
        "options": {
            ...
        },
        "configurations": {
          "production": {
           ...
          },
          "es5": {
            "browserTarget": "yourAppName:build:es5"
          }
        }
      },
      
    3. 使用以下命令使用此配置运行服务:

      ng serve --configuration es5
      

    【讨论】:

      【解决方案3】:
      • 取消注释 polyfill.ts 文件中的某些导入。
      • 安装几个 npm 包。
      • 修改 browserslist 文件(带有 Angular 11 项目的browserslistrc 文件)。

      取消注释 \src\polyfills.ts 下的几行

      // import 'classlist.js';  // Run `npm install --save classlist.js`.
      
      // import 'web-animations-js';  // Run `npm install --save web-animations-js`.
      

      安装几个 npm 包。

      npm install --save classlist.js
      npm install --save web-animations-js
      

      修改 browserslist 文件。

      搜索下一行。

      not IE 9-11 # For IE 9-11 support, remove 'not'.
      

      删除not关键字。

      IE 9-11 # For IE 9-11 support, remove 'not'.
      

      使用 Angular 11 browserslistrc 文件

      not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.
      

      删除not关键字。

      IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.
      

      【讨论】:

        猜你喜欢
        • 2018-12-14
        • 2018-03-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多