angular build error: TypeError: Cannot read proper

2019-05-24 12:19发布

问题:

I am suddenly facing build fail error for production. I am running this command:

ng build --prod

and getting following error:

D:\a\1\s\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:\a\1\s\node_modules\clean-css\lib\reader\input-source-map-tracker.js:37:23)
    at originalMetadata (D:\a\1\s\node_modules\clean-css\lib\tokenizer\tokenize.js:486:43)
    at intoTokens (D:\a\1\s\node_modules\clean-css\lib\tokenizer\tokenize.js:435:68)
    at tokenize (D:\a\1\s\node_modules\clean-css\lib\tokenizer\tokenize.js:74:10)
    at fromStyles (D:\a\1\s\node_modules\clean-css\lib\reader\read-sources.js:147:12)
    at fromString (D:\a\1\s\node_modules\clean-css\lib\reader\read-sources.js:48:10)
    at doReadSources (D:\a\1\s\node_modules\clean-css\lib\reader\read-sources.js:33:12)
    at readSources (D:\a\1\s\node_modules\clean-css\lib\reader\read-sources.js:24:10)
    at D:\a\1\s\node_modules\clean-css\lib\clean.js:99:12
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
Error: C:\Program Files\Git\bin\bash.exe failed with return code: 1

It used to work fine a few days ago but suddenly stopped working. Does any body have idea that why is this happening?

(I am using angular cli version 1.6.7)

Thanks in advance

回答1:

Alright! It's confirmed that this is happening in latest version of angular cli.

I finally fixed my issue by lowering version to 1.6.7 and by removing ^ I was facing this issue even after lowering version:

"@angular/cli": "^1.6.7"

Then I removed ^ to fix the cli version and now it works fine.

I request angular team that please fix this angular cli issue so that we can use latest versions.

I hope this would help.



回答2:

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.



回答3:

Issue got resolved

ng build --env=prod solves the problem no need to downgrade angular cli version