Angular 5 : ng build - -prod fails due to clean-css : Cannot read property 'line' of undefined

百般思念 提交于 2019-11-29 13:47:28

Run your sass/css files to show all space characters. I am pretty sure there is a non-breaking space somewhere between your properties which is causing it to break. something like

{
  color:[non-breaking-space]#123456;
}

You can spot these bad characters by installing a VS code plugin called Highlight Bad Chars https://marketplace.visualstudio.com/items?itemName=wengerk.highlight-bad-chars

TL;DR: Use an editor to find non-breaking spaces and eliminate them.

While it seems clean-css is failing fantastically after @angular/cli 1.6.7, this issue can be resolved for later versions of @angular/cli, regardless.

I got a lead on this issue being caused by non-breaking spaces: https://github.com/jakubpawlowicz/clean-css/issues/1006

I was then able to resolve the issue by opening the src/ folder as a workspace in Notepad++, filtering on *.scss and *.css, and doing a search with Regex on using \xA0 to find non-breaking spaces in the scss/css files; I found one. Once removed, my error went away.

For those that want to know how to accomplish this in Notepad++ in detail:

  1. File > Open Folder as Workspace... ; choose your folder containing your code
  2. In the Folder as Workspace window, right-click the folder and choose "Find in Files"
  3. in the "Find what" window, put \xA0
  4. In the "Filters" window, put *.scss *.css
  5. Under the "Search Mode" field set at the bottom, select "Regular expression"
  6. Click "Find All" and your offending non-breaking space locations should show up in the find window. Double-click on them to go to them and then delete and save.
  7. Profit.

Used js-beautify (https://github.com/beautify-web/js-beautify)

npm -g install js-beautify

Then cd to /src.

Then create .jsbeautifyrc en /src path.

{
"css": {
    "allowed_file_extensions": [
        "css",
        "scss",
        "sass",
        "less"
    ],
    "end_with_newline": false,
    "indent_char": " ",
    "indent_size": 4,
    "newline_between_rules": true,
    "selector_separator": " ",
    "selector_separator_newline": false,
    "preserve_newlines": false,
    "max_preserve_newlines": 1
}

}

And finally apply to all .scss files (or .css if you have them)

In Windows I used: FORFILES /S /M *.scss /C "cmd /c css-beautify -r -f @file"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!