1.7.0 wont prod build: cannot read property line of undefined
Small dependencies problem I guess.
Versions
Angular CLI: 1.7.0-beta.1
Node: 8.9.4
OS: darwin x64
Angular: 5.2.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.7.0-beta.1
@angular-devkit/build-optimizer: 0.0.41
@angular-devkit/core: 0.0.28
@angular-devkit/schematics: 0.0.51
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.10.0-beta.1
@schematics/angular: 0.1.16
typescript: 2.5.3
webpack-bundle-analyzer: 2.9.2
webpack: 3.10.0
Repro steps
- Fresh project using CLI
v1.7.0-beta.1 ng build --prod
Observed behavior
The code won't compile at all. An error in modules.
/project/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 (/project/node_modules/clean-css/lib/reader/input-source-map-tracker.js:37:24)
at originalMetadata (/project/node_modules/clean-css/lib/tokenizer/tokenize.js:486:43)
at intoTokens (/project/node_modules/clean-css/lib/tokenizer/tokenize.js:435:68)
at tokenize (/project/node_modules/clean-css/lib/tokenizer/tokenize.js:74:10)
at fromStyles (/project/node_modules/clean-css/lib/reader/read-sources.js:147:12)
at fromString (/project/node_modules/clean-css/lib/reader/read-sources.js:48:10)
at doReadSources (/project/node_modules/clean-css/lib/reader/read-sources.js:33:12)
at readSources (/project/node_modules/clean-css/lib/reader/read-sources.js:24:10)
at /project/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)
Mention any other details that might be useful
Tried to delete package-lock.json, delete node_modules, fresh reinstall. Same problem. Also tried yarn with no success.
Reverting to previous version make the error disappear.
It doesn't change the fact having scss which previously compiled and which seems correct. In the example mentionned above, MisterEffix case:
.is-loading .spinner {
transition: 0.2s margin ease-in,
.4s opacity ease-in;
margin-left: 5px;
opacity: 1;
}
is a common way to write long statements. It's not incorrect and should therefore not break the build.
Maybe helpful for any VSCode user: Installing this beautity extension and format all SCSS files with it has fixed the issue.
Finally manage to get the one who threw the error: it was a non-breaking space in the scss.
Definitely, this should'nt break that way hard.
@asadsahi In my case, the VSCode Beautify extension fixed the compile issue but the resulting CSS produced didn't seem right.
I agree that the SCSS compiler is improperly handling whitespace and/or should allow more flexibility with technically incorrect CSS. However, this is an issue with clean-css module, not Angular and so reporting it here really isn't going to get much traction. Not trying to be dismissive, just suggesting a better place to focus these issues.
@jacobslusser you are right. I will close the comment and report it to clean-css instead
@jacobslusser that is even more worrying to see the differences in rendering.
@jamieathans, we'll check Ultima theme. Thanks a lot!
@mertsincan I found out the issue with the Ultima theme.
Line 487 of assets/sass/theme/_data.scss contains a bad character.

By reformatting and removing the bad character, the border-color: $accentColor starts actually working and thus we see this being applied in the output.
Personally, I prefer it the original way which is basically border-color: inherit.
@jamieathans how do you lint this??
I have same problem with materialize-css (using dist/css), on ng build
92% chunk asset optimization/Users/elporfirio/Projects/temu-fidelizacion-cms-nodejs/source/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 (/Users/elporfirio/Projects/temu-fidelizacion-cms-nodejs/source/node_modules/clean-css/lib/reader/input-source-map-tracker.js:37:23)
at originalMetadata (/Users/elporfirio/Projects/temu-fidelizacion-cms-nodejs/source/node_modules/clean-css/lib/tokenizer/tokenize.js:486:43)
at intoTokens (/Users/elporfirio/Projects/temu-fidelizacion-cms-nodejs/source/node_modules/clean-css/lib/tokenizer/tokenize.js:435:68)
at tokenize (/Users/elporfirio/Projects/temu-fidelizacion-cms-nodejs/source/node_modules/clean-css/lib/tokenizer/tokenize.js:74:10)
at fromStyles (/Users/elporfirio/Projects/temu-fidelizacion-cms-nodejs/source/node_modules/clean-css/lib/reader/read-sources.js:147:12)
at fromString (/Users/elporfirio/Projects/temu-fidelizacion-cms-nodejs/source/node_modules/clean-css/lib/reader/read-sources.js:48:10)
at doReadSources (/Users/elporfirio/Projects/temu-fidelizacion-cms-nodejs/source/node_modules/clean-css/lib/reader/read-sources.js:33:12)
at readSources (/Users/elporfirio/Projects/temu-fidelizacion-cms-nodejs/source/node_modules/clean-css/lib/reader/read-sources.js:24:10)
at /Users/elporfirio/Projects/temu-fidelizacion-cms-nodejs/source/node_modules/clean-css/lib/clean.js:99:12
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
@elporfirio I had to go through my scss/css manually to find out which one was causing the problem.
The VSCode Highlight Bad Chars plugin showed me where the problem was.

@jamieathans thank you.
Alternative method don't add css/sass to angular.cli , instead copy css to assets folder, and add respective link to index.html.
It is ugly, but it can help while library gets an update.
I wonder how quickly it will be fixed upstream; if it's not quick, it will be wonderful to have CLI put in some kind of workaround. It's currently a remarkably unpleasant development experience when this happens.
Would be great if angular team, at scss compile step, could regex and remove all non-breaking spaces.
You can follow the issue on https://github.com/jakubpawlowicz/clean-css/issues/1006
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"
any update on this?
replace the code in node_modules/clean-css/lib/reader/input-source-map-tracker.js with the following
var SourceMapConsumer = require('source-map').SourceMapConsumer;
function inputSourceMapTracker() {
var maps = {};
return {
all: all.bind(null, maps),
isTracking: isTracking.bind(null, maps),
originalPositionFor: originalPositionFor.bind(null, maps),
track: track.bind(null, maps)
};
}
function all(maps) {
return maps;
}
function isTracking(maps, source) {
return source in maps;
}
function originalPositionFor(maps, metadata, range, selectorFallbacks) {
var line = metadata[0];
var column = metadata[1];
var source = metadata[2];
var position = {
line: line,
column: column + range
};
var originalPosition;
while (!originalPosition && position.column > column) {
position.column--;
originalPosition = maps[source].originalPositionFor(position);
}
if (originalPosition && originalPosition.line === null && line > 1 && selectorFallbacks > 0) {
return originalPositionFor(maps, [line - 1, column, source], range, selectorFallbacks - 1);
}
return (originalPosition && originalPosition.line) !== null ?
toMetadata(originalPosition) :
metadata;
}
function toMetadata(asHash) {
if(asHash){
return [asHash.line, asHash.column, asHash.source];
}
}
function track(maps, source, data) {
maps[source] = new SourceMapConsumer(data);
}
module.exports = inputSourceMapTracker;
```
It's now fixed as per clean-css 4.1.10 release just few hours ago. So it it occurs again on your side, just let npm install CLI with latest clean-css version. It should work.
I still have this issue with the version 1.7.1 of the CLI which is installed with clean-css 4.1.9