【问题标题】:Angular 4, Unexpected token: name (Subject) during ng build --prodAngular 4,意外令牌:ng build --prod 期间的名称(主题)
【发布时间】:2017-10-12 10:10:32
【问题描述】:

我有一个 Angular 4 应用程序。

我可以通过ng build成功构建项目

但是,当我运行ng build --prod 时,会抛出以下错误。

来自 UglifyJs 的 vendor.4008cf7dff2b98412878.bundle.js 中的错误 意外标记:名称(主题) [vendor.4008cf7dff2b98412878.bundle.js:19471,6]

当我进行一些研究时,我发现 uglifyjs 无法与 es6 一起使用,因此我在 tsconfig 文件中将目标更改为 es5。

但我不断收到此错误。

我不明白出了什么问题。

这里是 angular-cli 版本

这是我的 tsconfig.json 文件

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ],
    "paths": {
      "@angular/*": [
        "../node_modules/@angular/*"
      ]
    }
  }
}

这是我的 angular-cli.json 文件

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "myapp"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "styles.css",
        "../node_modules/sweetalert2/dist/sweetalert2.css",
        "../node_modules/ladda/dist/ladda-themeless.min.css"
      ],
      "scripts": [
        "../node_modules/crypto-js/crypto-js.js",
        "../src/assets/js/jquery-2.1.1.js",
        "../src/assets/js/plugins/datatables/jquery.dataTables.min.js",
        "../src/assets/js/plugins/datatables/dataTables.fixedColumns.min.js",
        "../src/assets/js/bootstrap.min.js",
        "../src/assets/js/plugins/metisMenu/jquery.metisMenu.js",
        "../src/assets/js/plugins/mask/jquery.mask.min.js",
        "../src/assets/js/plugins/slimscroll/jquery.slimscroll.min.js",
        "../src/assets/js/plugins/chartJs/Chart.min.js",
        "../src/assets/js/plugins/toastr/toastr.min.js",
        "../src/assets/js/plugins/datepicker/bootstrap-datepicker.js",
        "../src/assets/js/plugins/datepicker/bootstrap-datepicker.tr.js",
        "../src/assets/js/plugins/datetimepicker/jquery.datetimepicker.full.min.js",
        "../src/assets/js/plugins/iCheck/icheck.min.js",
        "../src/assets/js/plugins/chosen/chosen.jquery.min.js",
        "../src/assets/js/plugins/jsTree/jstree.min.js",
        "../src/assets/js/plugins/nestable/jquery.nestable.js",
        "../src/assets/js/plugins/colorpicker/bootstrap-colorpicker.min.js",
        "../src/assets/js/jasny-bootstrap.min.js",
        "../src/assets/js/inspinia.js",
        "../src/assets/js/custom.js"
      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "src/tsconfig.spec.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "e2e/tsconfig.e2e.json",
      "exclude": "**/node_modules/**"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "component": {}
  }
}

【问题讨论】:

    标签: angular angular-cli uglifyjs


    【解决方案1】:

    运行ng build --prod --sourcemaps 以识别导致问题的包。

    那么你需要找到一个解决方法。这就是挑战...

    【讨论】:

      【解决方案2】:

      我解决了这个问题。

      我使用了这个“aspnet/signalr-client”包。我从我的应用程序中卸载了包,问题已解决。

      现在,我可以使用ng build --prod 命令成功构建项目了。

      【讨论】:

        猜你喜欢
        • 2019-02-28
        • 2019-05-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-14
        • 2017-07-04
        相关资源
        最近更新 更多