ng build --prod issue

2019-02-25 07:27发布

问题:

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

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

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

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

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"
  }

回答1:

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

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

Also I've raised the typescript version to 2.1.6.