简体   繁体   中英

Angular Prod build failed with Clean Css Error

I am getting the below error when building my code, any fixes?

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

92% chunk asset optimizationD:\\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: Cannot read property 'line' of undefined 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) at doReadSources (D:\\myproject\\node_modules\\@angular\\cli\\node_modules\\clean-css\\lib\\reader\\read-sources.js:33:12) at readSources (D:\\myproject\\node_modules\\@angular\\cli\\node_modules\\clean-css\\lib\\reader\\read-sources.js:24:10) at D:\\myproject\\node_modules\\@a ngular\\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)

Here is my package.json snippet

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

}

These steps:

  1. npm uninstall @angular/cli
  2. npm install @angular/cli@1.6.8 --save-dev (which is the previous version: https://github.com/angular/angular-cli/releases )

fixed the issue for me.

The solution provided by MapLion here ( Angular 5 : ng build -- prod fails due to clean-css : Cannot read property 'line' of undefined ) should work fine.

TL;DR - Search for the character '\\xA0' in your CSS / SCSS files, and remove them so your build can succeed again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM