Angular 4, Unexpected token: name (Subject) during ng build --prod

时间:2017-10-12 10:10:33

标签: angular angular-cli uglifyjs

I have a Angular 4 application.

I can successfully build the project with ng build

But, when I run ng build --prod the following error is thrown.

ERROR in vendor.4008cf7dff2b98412878.bundle.js from UglifyJs Unexpected token: name (Subject) [vendor.4008cf7dff2b98412878.bundle.js:19471,6]

When I did some research, I saw uglifyjs not working with es6 and I changed target to es5 in my tsconfig file.

But I keep getting this error.

I don't understand what is wrong.

Here is angular-cli version

Angular CLI Version

Here is my tsconfig.json file

{
  "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/*"
      ]
    }
  }
}

And here is my angular-cli.json file

{
  "$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": {}
  }
}

2 个答案:

答案 0 :(得分:3)

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

然后你需要找到一个解决方法。这是挑战......

答案 1 :(得分:0)

我解决了这个问题。

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

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

相关问题