Angular 8 个应用程序不在 IE11 上 运行

Angular 8 application not running on IE11

我一直在尝试 运行 我的 Angular 8 应用程序在 IE11 上运行。 到目前为止,我已经尝试了本文中所述的所有步骤, Angular 8 and IE 11

并且仍然像这张图片一样出现错误 ->IE console

以下是相关文件:

Polyfills.ts:

    /***************************************************************************************************
 * BROWSER POLYFILLS
 */


/** IE10 and IE11 requires the following for NgClass support on SVG elements */

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


/*

 * 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`.

** IE9, IE10 and IE11 requires all of the following polyfills. **/

import 'core-js/es/symbol';

import 'core-js/es/promise';

import 'core-js/es/object';

import 'core-js/es/function';

import 'core-js/es/parse-int';

import 'core-js/es/parse-float';

import 'core-js/es/number';

import 'core-js/es/math';

import 'core-js/es/string';

import 'core-js/es/date';

import 'core-js/es/array';

import 'core-js/es/regexp';

import 'core-js/es/map';

import 'core-js/es/weak-map';

import 'core-js/es/set';

import 'zone.js/dist/zone';  // Included with Angular CLI.

浏览器列表:

// > 0.5%

last 2 versions

Firefox ESR

not dead

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

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": "es5",

    "typeRoots": [

      "node_modules/@types"

    ],

    "lib": [

      "es2018",

      "dom"

    ]
  },

  "angularCompilerOptions": {

    "fullTemplateTypeCheck": true,

    "strictInjectionParameters": true
  }
}

WEB.CONFIG:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301879
  -->
<configuration>
  <connectionStrings>
   
  </connectionStrings>
  <system.web>
    <customErrors mode="Off"></customErrors>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" maxRequestLength="100000" />
  </system.web>
 <appSettings>
  
  
 </appSettings>

<system.webServer>
 

     <modules>
      <remove name="UrlRewriteModule" />
        <remove name="UmbracoModule" />
        <remove name="ClientDependencyModule" />
        <remove name="ImageProcessorModule" />
    </modules>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
      <remove name="OPTIONSVerbHandler"/>
      <remove name="TRACEVerbHandler"/>
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler"
        preCondition="integratedMode,runtimeVersionv4.0"/>
    </handlers>


    <rewrite>
            <rules>
                <rule name="AddTrailingSlashRule1" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                            <!-- <add input="{REQUEST_URI}" matchType="^/(api)" negate="true" /> -->
                    </conditions>
                    <action type="Rewrite" url="/motorclaims/"  />
                </rule>
            </rules>
        </rewrite>

  </system.webServer>

  </configuration>

ANGULAR.JSON:

{

  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",

  "version": 1,

  "newProjectRoot": "projects",

  "projects": {

    "sample": {

      "projectType": "application",
      "schematics": {

        "@schematics/angular:component": {

          "style": "scss"

        }

      },
      "root": "",

      "sourceRoot": "src",

      "prefix": "app",

      "architect": {
        "build": {

          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/sample",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": false,
            "assets": [
              "src/favicon.ico",
              "src/assets",
              "src/web.config"
            ],
            "styles": [
              "src/styles.scss",
              "src/assets/css/datepicker.min.css"
            ],
            "scripts": [
              "src/assets/js/jquery-3.4.1.min.js",
              "src/assets/js/jquery.mb.slider.js",
              "src/assets/js/jquery.validate.min.js",
              "src/assets/js/materialize.js",
              "src/assets/js/messages.js",
              "src/assets/js/select.js",
              "src/assets/js/new_date_picker.js",
              
              "src/assets/js/sample.js",
              "src/assets/Loader.hyperesources/loader_hype_generated_script.js",
              "src/assets/Loader.hyperesources/HYPE-674.thin.min.js"
            ]
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            },
            "uat":{
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.uat.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "sample:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "sample:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "sample:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "sample:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "sample:serve:production"
            },
            "uat": {
              "devServerTarget": "sample"
            }
          }
        }
      }
    }
  },
  "defaultProject": "sample"
  
}

PACKAGE.JSON

  {

  "name": "sample",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~8.2.0",
    "@angular/common": "~8.2.0",
    "@angular/compiler": "~8.2.0",
    "@angular/core": "~8.2.0",
    "@angular/forms": "~8.2.0",
    "@angular/http": "^7.2.16",
    "@angular/material": "^9.2.1",
    "@angular/platform-browser": "~8.2.0",
    "@angular/platform-browser-dynamic": "~8.2.0",
    "@angular/router": "~8.2.0",
    "@babel/compat-data": "^7.8.0",
    "@types/jquery": "^3.3.36",
    "classlist.js": "^1.1.20150312",
    "jquery": "^3.5.0",
    "moment": "^2.27.0",
    "ngx-image-compress": "^8.0.4",
    "rxjs": "~6.4.0",
    "rxjs-compat": "^6.5.5",
    "tslib": "^1.10.0",
    "web-animations-js": "^2.3.2",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.803.24",
    "@angular/cli": "~8.2.0",
    "@angular/compiler-cli": "~8.2.0",
    "@angular/language-service": "~8.2.0",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.0.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3"
  }
}

**此外,该解决方案应该适用于 ng build。

谢谢你帮助我。对我有用的解决方案正在改变

"target": "es2015",

"target": "es5",

tsconfig.json 文件中。此外,这之前对我不起作用,因为我在导致错误的资产中有一个脚本文件。一旦我将它从项目中删除,它在 IE11 上运行良好。 因此,为了将来参考,请在对 IE11 进行任何更改之前检查您的资产文件,以避免此类错误。