Angular 5 丑陋构建返回错误



我将我的SPA从Angular 4更新到Angular 5,其中包含所有依赖项。到目前为止效果很好。开发和生产构建工作得很好。没有错误或警告。

当我使用--prod标志构建 SPA 时,angular-cli会使构建变得丑陋。没有来自angular-cli的错误。但是当我在浏览器中打开SPA时,我遇到了错误,没有任何反应。页面根本不加载(仅加载微调器(。

Uncaught Error: Unexpected value 'Ie' imported by the module 't'. Please add a @NgModule annotation.
at c (compiler.js:466)
at compiler.js:15088
at Array.forEach (<anonymous>)
at t.getNgModuleMetadata (compiler.js:15071)
at t.getNgModuleSummary (compiler.js:14998)
at compiler.js:15086
at Array.forEach (<anonymous>)
at t.getNgModuleMetadata (compiler.js:15071)
at t._loadModules (compiler.js:33486)
at t._compileModuleAndComponents (compiler.js:33447)

这是我对所有依赖项和构建脚本package.json

{
    "name": "broadcast-manager",
    "version": "0.1.0",
    "license": "MIT",
    "scripts": {
        "ng": "ng",
        "dev": "ng serve --dev --environment main --port 1337 --host 0.0.0.0 --proxy-config proxy.conf.json",
        "prod": "ng build --prod --environment main --aot false"
    },
    "private": true,
    "dependencies": {
        "@angular/animations": "^5.0.1",
        "@angular/cli": "^1.5.0",
        "@angular/common": "^5.0.1",
        "@angular/compiler": "^5.0.1",
        "@angular/compiler-cli": "^5.0.1",
        "@angular/core": "^5.0.1",
        "@angular/forms": "^5.0.1",
        "@angular/http": "^5.0.1",
        "@angular/platform-browser": "^5.0.1",
        "@angular/platform-browser-dynamic": "^5.0.1",
        "@angular/router": "^5.0.1",
        "@swimlane/ngx-charts": "^6.1.0",
        "@swimlane/ngx-datatable": "^11.0.4",
        "@types/jwt-decode": "^2.2.1",
        "@types/node": "^8.0.53",
        "bootstrap": "4.0.0-alpha.6",
        "codelyzer": "^4.0.1",
        "core-js": "^2.5.1",
        "d3": "^4.11.0",
        "jwt-decode": "2.2.0",
        "moment": "^2.19.2",
        "ng2-dnd": "^4.2.0",
        "ngx-bootstrap": "^2.0.0-beta.8",
        "ngx-chips": "^1.5.9",
        "node-sass": "^4.6.1",
        "protractor": "^5.2.0",
        "rxjs": "^5.5.2",
        "ts-node": "^3.3.0",
        "tslint": "^5.8.0",
        "typescript": "^2.6.1",
        "zone.js": "^0.8.18"
    },
    "devDependencies": {}
}

这是我的.angular-cli.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "broadcast"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "../public/frontend",
      "assets": [
        "assets",
        ".htaccess",
        "favicon.ico",
        {
  "glob": "**/*",
  "input": "../node_modules/font-awesome/fonts/",
  "output": "./assets/fonts/"
}
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "prefix": "bm-",
      "environmentSource": "environments/environment.ts",
      "environments": {
        "main": "environments/environment.ts"
      }
    }
  ],
  "lint": [
    {
      "project": "src/tsconfig.app.json"
    }
  ],
  "defaults": {
    "styleExt": "css",
    "component": {
    }
  },
  "warnings": {
    "typescriptMismatch": false
  }
}

如何调试正在发生/出错的情况?

由于 @Kevin RED,我通过以下简单的解决方案解决了这个问题。

以前:

"scripts": {
    "prod": "ng build --prod --aot false"
}

后:

"scripts": {
    "prod": "ng build --prod --aot false --build-optimizer=false"
}

我现在不确定build-optimizer的功能是什么(npmjs-build-optimizer(,但是如果我将其设置为 true ,则会收到错误。设置false,它可以工作。

最新更新