【问题标题】:Angular IE11 not working. Getting SCRIPT1002 Syntax ErrorAngular IE11 不工作。获取 SCRIPT1002 语法错误
【发布时间】:2019-03-07 15:50:15
【问题描述】:

试图让 Angular 在 IE 11 中工作。 我已经尝试了我在网上找到的所有内容。

我收到以下错误:

SCRIPT1002:语法错误

文件:polyfills.js,行:2358,列:1

第 2358 行

class Disposable {

    /**
     * Frees internal resources.
     */

    dispose() {}

}

SCRIPT1002:语法错误

文件:scripts.js,行:424,列:35

第 424 行

let SoapService = SoapService_1 = class SoapService {
    constructor(servicePort, servicePath, targetNamespace) {
        this.debug = false;
        this.asynchronous = true;
        this.localName = false;
        this.servicePort = '';
        this.servicePath = '';
        this.serviceUrl = '';
        this.targetNamespace = '';
        this.envelopeBuilder_ = null;
        this.xmlResponseHandler_ = null;
        this.jsoResponseHandler_ = null;
        this.servicePort = servicePort;
        this.servicePath = servicePath;
        this.serviceUrl = servicePort + servicePath;
        if (undefined !== targetNamespace)
            this.targetNamespace = targetNamespace;
    }

SCRIPT1002:语法错误

文件:vendor.js,行:88,列:1

第 88 行

class AnimationBuilder {
}

SCRIPT1002:语法错误

文件:main.js,行:91422,列:35

第91422行同上

    let SoapService = SoapService_1 = class SoapService {
        constructor(servicePort, servicePath, targetNamespace) {
....

我确实有一个肥皂连接,它无论如何都不能在本地主机上工作。所以这可能不是问题

在 main.ts 中添加了这一行

/// <reference path= "../node_modules/typescript/lib/lib.es6.d.ts" />

在 index.html 中添加了这个脚本

<script src="/node_modules/core-js/client/shim.min.js"></script>

tsconfig.json

{
  "compileOnSave": false,

  "compilerOptions": 
  {
    "forceConsistentCasingInFileNames":true,
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom",
      "es5",
      "es6"
    ]
  },

  "files": [
    "src/app/app.module.ts"
  ],

  "include": [
    "src/**/*"
  ]
}

我还有一个 tsconfig.app.json 和 tsconfig.spec.json

polyfills.js

/**
 * This file includes polyfills needed by Angular and is loaded before the app.
 * You can add your own extra polyfills to this file.
 *
 * This file is divided into 2 sections:
 *   1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
 *   2. Application imports. Files imported after ZoneJS that should be loaded before your main
 *      file.
 *
 * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
 * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
 * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
 *
 * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
 */

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

/** IE9, IE10 and IE11 requires all of the following 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/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`.

/** IE10 and IE11 requires the following for the Reflect API. */
import 'core-js/es6/reflect';


/** Evergreen browsers require these. **/
// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.



/**
 * Required to support Web Animations `@angular/platform-browser/animations`.
 * 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 default for Angular itself.
 */
import 'zone.js/dist/zone';  // Included with Angular CLI.



/***************************************************************************************************
 * APPLICATION IMPORTS
 */
import 'three';
import 'three-orbitcontrols-ts';
import 'postprocessing';

package.json

{
  "name": "regalplaner",
  "version": "1.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^7.2.1",
    "@angular/common": "^7.0.0",
    "@angular/compiler": "^7.0.0",
    "@angular/core": "^7.0.0",
    "@angular/forms": "^7.0.0",
    "@angular/http": "^7.0.0",
    "@angular/platform-browser": "^7.0.0",
    "@angular/platform-browser-dynamic": "^7.0.0",
    "@angular/router": "^7.0.0",
    "@tweenjs/tween.js": "^17.2.0",
    "@types/three": "^0.92.20",
    "autopulous-angular2-soap": "^0.4.7",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.4.1",
    "dat.gui": "^0.7.5",
    "es6-tween": "^5.3.0",
    "n": "^2.1.12",
    "ng-drag-drop": "^5.0.0",
    "ng2-drag-drop": "^3.0.2",
    "ngx-color-picker": "^6.7.0",
    "normalize.css": "^5.0.0",
    "postprocessing": "^5.3.1",
    "rxjs": "^6.3.3",
    "rxjs-compat": "^6.3.3",
    "stats-js": "^1.0.0",
    "three": "^0.94.0",
    "three-addons": "^1.2.0",
    "three-gltf-loader": "^1.102.0",
    "three-orbitcontrols-ts": "^0.1.2",
    "tween.js": "^16.6.0",
    "web-animations-js": "^2.3.1",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.10.0",
    "@angular/cli": "^7.0.1",
    "@angular/compiler-cli": "^7.0.0",
    "@angular/language-service": "^7.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "^5.4.1",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~3.1.3"
  }
}

【问题讨论】:

  • 每行抛出错误的代码是什么?
  • @sgunliffe 已更新
  • 更新到最新的 cli 创建一个新的 cli 项目进入 polyfills.ts 并取消注释行:22 - 35。运行 ng serve 并检查是否有效

标签: angular internet-explorer


【解决方案1】:

对于遇到类似问题的其他人:

Angular 8 已将默认目标设为 es2015 而不是 es5

您需要创建一个tsconfig.es5.json,以便仅在开发模式下在 es5 上运行,但可以在此处找到更多信息:https://github.com/angular/angular-cli/issues/14455

您还需要取消注释 polyfills.ts 中的 polyfill,具体取决于您使用的内容。

对于其他人和提问者:

然后,您需要向 zone.js 添加一个标志

添加import './zone-flags.ts'; 之前import 'zone.js/dist/zone'; 然后在与polyfills.ts 相同的目录中创建zone-flags.ts 文件。

zone-flags.ts 文件中添加以下行:

(window as any).__Zone_enable_cross_context_check = true;

希望之后一切正常!如果你按照上面的链接,

执行:ng serve --configuration es5 以开发模式在 IE 中运行您的项目。


更新

看起来 Angular 实际上有这方面的文档: angular.io/guide/deployment#fallback

查找“旧浏览器中的本地开发”,然后查找“为 ES5 配置服务”

问题是由 Angular 8 的不同加载过程引起的。

【讨论】:

    【解决方案2】:

    看起来您正在使用或传递您的 JavaScript,但还远远不够,并且您遇到语法问题,因为您尝试使用 IE11 不支持的功能。

    例如

    【讨论】:

      【解决方案3】:

      要完成@Lionheart Scholar 所说的,还有最后一步:在 tsconfig.app.json "files" 部分注册 zone-flags.ts 文件,如下所示:

      {
        "extends": "./tsconfig.json",
        "compilerOptions": {
          "outDir": "./out-tsc/app",
          "types": []
        },
        "files": [
          "src/main.ts",
          "src/polyfills.ts",
          "src/zone-flags.ts"
        ],
        "include": [
          "src/**/*.d.ts"
        ]
      }
      

      【讨论】:

        【解决方案4】:

        在 tsconfig.json 替换“目标”:“es5”, //"目标": "es2015",

        【讨论】:

        • 如果你忘记了。您的构建将使用 es5。
        猜你喜欢
        • 1970-01-01
        • 2020-05-21
        • 1970-01-01
        • 2020-02-02
        • 1970-01-01
        • 2019-04-04
        • 2019-10-09
        • 2021-11-11
        • 2018-05-20
        相关资源
        最近更新 更多