Angular应用程序仅在IE11上引发语法错误

时间:2019-07-25 00:37:46

标签: angular internet-explorer

我有Angular应用程序,它仅在IE11上不起作用。

我已经设置了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/es7/array';
    import 'core-js/es6/regexp';
    import 'core-js/es6/map';
    import 'core-js/es6/weak-map';
    import 'core-js/es6/set';

启用tsconfig将代码转换为ES5

"target": "es5" 

许多时间更新了NPM模块。

将angularCli和angularCli从7降级到6

Angular CLI: 6.2.5
Node: 8.11.4
OS: win32 x64
Angular: 6.1.10
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.8.5
@angular-devkit/build-angular     0.8.5
@angular-devkit/build-optimizer   0.8.5
@angular-devkit/build-webpack     0.8.5
@angular-devkit/core              0.8.5
@angular-devkit/schematics        0.8.5
@angular/cdk                      7.1.0
@angular/cli                      6.2.5
@ngtools/webpack                  6.2.5
@schematics/angular               0.8.5
@schematics/update                0.8.5
rxjs                              6.2.2
typescript                        2.9.2
webpack                           4.20.2

Package.json依赖项

 "dependencies": {
    "@angular/cdk": "^7.3.7",
    "@angular/common": "^7.2.15",
    "@angular/compiler": "^7.2.15",
    "@angular/core": "^7.2.15",
    "@angular/forms": "^7.2.15",
    "@angular/material": "^8.0.1",
    "@angular/platform-browser": "^7.2.15",
    "@angular/platform-browser-dynamic": "^7.2.15",
    "@angular/router": "^7.2.15",
    "@ngrx/effects": "^6.1.0",
    "@ngrx/router-store": "^6.1.0",
    "@ngrx/store": "^7.4.0",
    "angular-web-storage": "^7.0.0-beta.1",
    "bootstrap": "^4.3.1",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.6.9",
    "intersection-observer": "^0.5.1",
    "jquery": "^3.4.1",
    "moment": "^2.24.0",
    "ngrx-store-logger": "^0.2.3",
    "ngx-cookie-service": "^2.2.0",
    "ngx-logger": "^3.3.13",
    "popper.js": "^1.15.0",
    "rxjs": "~6.3.3",
    "striptags": "^3.1.1",
    "tslib": "^1.10.0",
    "web-animations-js": "^2.3.2",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.13.9",
    "@angular/animations": "^7.2.15",
    "@angular/cli": "^7.3.9",
    "@angular/compiler-cli": "^7.2.15",
    "@angular/language-service": "^7.2.15",
    "@trv-ebus/tds": "^4.1.1",
    "@trv-ebus/tds-icons": "^2.0.5",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "node-sass": "file:src/external-deps/npm_modules/node-sass",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2"
  }

但是,除了IE11,其他都为syntax error in vendor.js and main.js

在调试时,它仅指向没有具体说明的aapRouteModules。

1 个答案:

答案 0 :(得分:1)

这种问题通常是由于缺乏填充料引起的。您还需要在 polyfills.ts 中取消注释以下Polyfill:

import 'classlist.js';
import 'web-animations-js';
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';

然后您需要使用npm安装一些软件包:

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

然后请在 index.html 中添加元标记:<meta http-equiv="X-UA-Compatible" content="IE=edge" />

如果您已按照上述步骤操作,但仍然无法使用,请确保未使用IE不支持的任何ES6语法,例如箭头函数=>。您也可以参考this thread中接受的答案,它解决了与您相同的问题。