本文介绍了ng build --prod 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用最新版本的 @angular/cli 并且在我的 Angular2 应用程序中有一个奇怪的错误.

I'm working with the latest version of @angular/cli and have a weird error in me Angular2 App.

进行 ng build --pro 后,bundle 无法正常工作,我可以在控制台中看到此错误:

After make a ng build --pro the bundle doesn't work properly, I can see this error in the console:

例外:无法设置只有 getter 的 # 的属性值

EXCEPTION: Cannot set property value of # which has only a getter

但是,进行无参数构建,工作正常,有什么想法吗?

But,making a no parameters build, works fine,any idea?

这是我的 package.json 的一大块

This is a chunk of my package.json

  "dependencies": {
    "@angular/common": "^2.4.6",
    "@angular/compiler": "^2.4.6",
    "@angular/core": "^2.4.6",
    "@angular/forms": "^2.4.6",
    "@angular/http": "^2.4.6",
    "@angular/platform-browser": "^2.4.6",
    "@angular/platform-browser-dynamic": "^2.4.6",
    "@angular/router": "^3.4.0",
    "body-parser": "^1.16.0",
    "btoa": "^1.1.2",
    "compression": "^1.6.2",
    "config": "^1.24.0",
    "core-js": "^2.4.1",
    "cors": "^2.8.1",
    "express": "^4.14.0",
    "express-minify": "^0.2.0",
    "express-uglify": "^0.3.1",
    "http-proxy-middleware": "^0.17.3",
    "jsonschema": "^1.1.1",
    "jsonwebtoken": "^7.2.1",
    "ng2-bootstrap": "^1.2.6",
    "nodemailer": "^2.7.2",
    "request": "^2.79.0",
    "request-ip": "^1.2.3",
    "request-promise": "^4.1.1",
    "rxjs": "^5.0.1",
    "ts-helpers": "^1.1.1",
    "winston": "^2.3.1",
    "zone.js": "^0.7.6"
  },
  "devDependencies": {
    "@angular/cli": "^1.0.0-beta.31",
    "@angular/compiler-cli": "^2.4.0",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "codelyzer": "~2.0.0-beta.1",
    "frisby": "^0.8.5",
    "jasmine-core": "2.5.2",
    "jasmine-node": "^1.14.5",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-coverage-istanbul-reporter": "^0.2.0",
    "karma-jasmine": "^1.0.2",
    "nodemon": "^1.11.0",
    "protractor": "~5.1.0",
    "ts-node": "1.2.1",
    "tslint": "^4.3.0",
    "typescript": "~2.0.0"
  }

推荐答案

在这张票的帮助下,我发现了问题……4720

I've found the problem... with the help of this ticket:4720

通过在 ng build 命令期间添加 --aot=false 关闭 aot 可以解决问题.

Turning aot off by adding --aot=false during the ng build command it fixes the problem.

此外,我已将打字稿版本提高到 2.1.6.

Also I've raised the typescript version to 2.1.6.

这篇关于ng build --prod 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 04:07