javascript - vendor.js 中的 SCRIPT1002 语法错误 - Angular 8 IE11

标签 javascript angular typescript ecmascript-6 internet-explorer-11

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

SCRIPT1002: Syntax error

File: vendor.js, Line: 110874, Column: 40


110874线
args[0].replace(/%[a-zA-Z%]/g, match => {
    if (match === '%%') {
        return;
    }
    index++;
    if (match === '%c') {
        // We only are interested in the *last* %c
        // (the user may have provided their own)
        lastC = index;
    }
});
我已经按照 Angular 进行了推荐的 es5 配置,并且我正在使用这些配置运行(https://angular.io/guide/deployment 配置为 ES5 服务)。
我的 polyfills.ts:
/** 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';
import 'web-animations-js';  // Run `npm install --save web-animations-js`.
import 'zone.js/dist/zone';  // Included with Angular CLI.
我的 tsconfig.json:
{
    "compileOnSave": false,
    "compilerOptions": {
        "baseUrl": "./",
        "outDir": "./dist/out-tsc",
        "sourceMap": true,
        "declaration": false,
        "module": "esnext",
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "importHelpers": true,
        "target": "es2015",
        "typeRoots": [
            "node_modules/@types"
        ],
        "lib": [
            "es2018",
            "dom"
        ]
    }
}
我的 tsconfig.es5.json:
{
    "extends": "./tsconfig.json",
    "compilerOptions": {
        "target": "es5" 
     }
   }
我正在使用 angular 8 和primeng;
我用 ng serve -- 配置 es5 运行;
更新 :
从我发现的问题来看,我正在使用的 socket-io-client 的依赖项会出现问题。稍微研究一下,问题似乎与 socket-io-client 的调试和 babel 依赖关系有关。我真的需要在我的系统上使用套接字,所以我仍在寻找解决方案。但是如果我删除 socket-io-client 它将正常运行。
我通过这两个话题找到了问题的根源:

https://github.com/visionmedia/debug/issues/729

https://github.com/babel/babel/issues/10707

最佳答案

问题是箭头函数没有成功转换。您是否按照 this answer 中的步骤进行操作?在 IE 11 中支持 Angular 8?如果您按照步骤操作,问题仍然存在,可能是因为您使用了包含箭头函数的外部 js 库。

Angular CLI 不会转译 Javascript 代码。第三方代码应采用适当的格式。您应该使用该库的 ES5 版本以使其与 IE 11 兼容。

您也可以引用this thread , 设置 lib"es5" , "es6" , "dom"看看它是否有效。如果不工作,只需使用 ES5 库版本。

-------------------------------------------------- - - - - - - - - - -编辑 - - - - - - - - - - - - - - - -------------------------------------------

您可以使用 exclude位于 webpack.config.js 的属性(property)或 babel.config.js转译模块。我们可以改变这一点:

...
  exclude: /node_modules/,
...

进入这个:
...
  exclude: /node_modules\/(?!name-of-untranspiled-module)/,
...

引用:How to handle npm modules which include es6

关于javascript - vendor.js 中的 SCRIPT1002 语法错误 - Angular 8 IE11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60076978/

相关文章:

unit-testing - 为单元测试模拟 BsModalRef

javascript - 多次填写同一表单字段的内容并将其写入数据库的多行中

javascript - AngularJS - ngRepeat 将所选行显示为事件状态

javascript - 全局样式不起作用 - vue.js

css - Angular Material : no background color on mat-input on focus mode

javascript - webpack 错误 : File to import not found or unreadable: bourbon , 如何解决?

javascript - Node.js 项目的 Typescript 中类的实例函数

javascript - 使用 asp.net 服务器端将现有 Javascript 代码转换为多语言?

Angular Material - 找不到名称 'MAT_FORM_FIELD_DEFAULT_OPTIONS'

typescript - Typescript --allowJs 如何工作?