Angular Prod构建因Clean Css Error而失败

时间:2018-02-16 21:22:08

标签: angular angular-cli clean-css

构建我的代码时,我遇到以下错误,是否有任何修复?

> ng build --prod --no-aot --base-href

92%的块资产优化D:\ myproject \ node_modules \ @angular \ cli \ node_modules \ clean-css \ lib \ reader \ input-source-map-tracker.js:37   if(originalPosition.line === null&& line> 1&& selectorFallbacks> 0){                        ^

TypeError:无法读取未定义的属性“line”     at originalPositionFor(D:\ myproject \ node_modules \ @angular \ cli \ node_modules \ clean-css \ lib \ reader \ input-source-map-tracker.js:37:24)     at originalMetadata(D:\ myproject \ node_modules \ @angular \ cli \ node_modules \ clean-css \ lib \ tokenizer \ tokenize.js:486:43)     at intoTokens(D:\ myproject \ node_modules \ @angular \ cli \ node_modules \ clean-css \ lib \ tokenizer \ tokenize.js:240:75)     at tokenize(D:\ myproject \ node_modules \ @angular \ cli \ node_modules \ clean-css \ lib \ tokenizer \ tokenize.js:74:10)     at fromStyles(D:\ myproject \ node_modules \ @angular \ cli \ node_modules \ clean-css \ lib \ reader \ read-sources.js:147:12)     at fromString(D:\ myproject \ node_modules \ @angular \ cli \ node_modules \ clean-css \ lib \ reader \ read-sources.js:48:10)     在doReadSources(D:\ myproject \ node_modules \ @angular \ cli \ node_modules \ clean-css \ lib \ reader \ read-sources.js:33:12)     在readSources(D:\ myproject \ node_modules \ @angular \ cli \ node_modules \ clean-css \ lib \ reader \ read-sources.js:24:10)     在D:\ myproject \ node_modules \ @angular \ cli \ node_modules \ clean-css \ lib \ clean.js:99:12     at _combinedTickCallback(internal / process / next_tick.js:131:7)     at process._tickCallback(internal / process / next_tick.js:180:9)

这是我的package.json片段

"dependencies": {
"@agm/core": "^1.0.0-beta.2",
"@angular/animations": "^5.2.5",
"@angular/common": "^5.2.5",
"@angular/compiler": "^5.2.5",
"@angular/core": "^5.2.5",
"@angular/forms": "^5.2.5",
"@angular/http": "^5.2.5",
"@angular/platform-browser": "^5.2.5",
"@angular/platform-browser-dynamic": "^5.2.5",
"@angular/platform-server": "^5.2.5",
"@angular/router": "^5.2.5",
"@auth0/angular-jwt": "^1.0.0-beta.10",
"@ng-bootstrap/ng-bootstrap": "^1.0.0",
"@swimlane/ngx-charts": "^7.1.0",
"@types/toastr": "^2.1.35",
"angular": "^1.6.9",
"angular-chartist.js": "^4.3.4",
"angular2-chartjs": "^0.3.0",
"angular2-jwt": "^0.2.3",
"angular2-moment": "^1.8.0",
"bootstrap": "4.0.0-beta.2",
"chart.js": "^2.7.0",
"chart.piecelabel.js": "^0.9.0",
"chartist": "^0.11.0",
"chartjs-plugin-piechart-outlabels": "^0.1.4",
"core-js": "^2.4.1",
"d3": "^4.13.0",
"d3-ng2-demo": "^0.2.0",
"font-awesome": "^4.7.0",
"google-libphonenumber": "^2.0.15",
"jquery": "^3.3.1",
"moment-timezone": "^0.5.14",
"ng2-charts": "^1.6.0",
"ngx-intl-tel-input": "^1.0.6",
"popper": "^1.0.1",
"popper.js": "^1.13.0",
"primeng": "^5.2.0",
"roboto-fontface": "^0.8.0",
"rxjs": "^5.5.5",
"tether": "^1.4.3",
"toastr": "^2.1.4",
"zone.js": "^0.8.20"

}

,"devDependencies": {
"@angular/cli": "^1.7.0",
"@angular/compiler-cli": "^5.2.5",
"@angular/language-service": "^4.0.0",
"@types/bootstrap": "^3.3.38",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "^6.0.101",
"clean-css": "^4.0.13",
"codelyzer": "~3.0.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "^1.7.1",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.4.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.0.4",
"tslint": "~5.3.2",
"typescript": "^2.4.2"

}

2 个答案:

答案 0 :(得分:0)

这些步骤:

  1. npm uninstall @ angular / cli
  2. npm install @ angular / cli @ 1.6.8 --save-dev(以前的版本:https://github.com/angular/angular-cli/releases
  3. 为我解决了这个问题。

答案 1 :(得分:0)

MapLion在这里提供的解决方案(Angular 5 : ng build -- prod fails due to clean-css : Cannot read property 'line' of undefined)应该可以正常工作。

TL; DR - 搜索角色' \ xA0'在您的CSS / SCSS文件中,删除它们,以便您的构建可以再次成功。