angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

1.7.0 wont prod build: cannot read property line of undefined

Open blackholegalaxy opened this issue 8 years ago • 44 comments

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.

blackholegalaxy avatar Jan 22 '18 11:01 blackholegalaxy

I can't replicate this with a new project created with 1.7.0-beta.1. Tried the following all with success:

  • ng build
  • ng build --prod
  • ng build --prod --sourcemap

webpack-bundle-analyzer appears to be in the version output in the issue report. This is not part of a new project. Are there any other changes to the project that were made?

clydin avatar Jan 22 '18 14:01 clydin

Installed bundle analyser to compare the bundle size with 1.6.3 (see my other opened issue). The only change was to add a lazy loaded route with only one component. And move from css to scss.

blackholegalaxy avatar Jan 22 '18 15:01 blackholegalaxy

Does the error occur on a new project with no changes?

clydin avatar Jan 22 '18 15:01 clydin

Tried that 3 times on brand new project. 1 fail, 2 normal build. I tried to remove node modules and npm install between each try

blackholegalaxy avatar Jan 22 '18 15:01 blackholegalaxy

The described error occurs with

x Angular cli 1.7.0-beta1 (did not occur with 1.6.5) x --prod option.

and...

a CSS property written in two lines

Example from my project :

.is-loading .spinner {
   transition: 0.2s margin ease-in, 
      .4s opacity ease-in;
  margin-left: 5px;
  opacity: 1;
}

vs

.is-loading .spinner {
   transition: 0.2s margin ease-in, .4s opacity ease-in;
  margin-left: 5px;
  opacity: 1;
}

If it can help somebody, I found where was my problematic css property by adding console.log(serializedBuffer) at node_modules/clean-css/lib/tokenizer/tokenizer.js : line 434.

ghost avatar Jan 24 '18 17:01 ghost

Thanks @MisterEffix, it can be a real good lead. I tried to reproduce using a splitted css and it fails every and each time I build --prod. Thanks!

blackholegalaxy avatar Jan 24 '18 18:01 blackholegalaxy

@MisterEffix thanks, i faced the same issue, which i solved following your advice, i had

p,
ul,
{
    text-align: justify;
}

which i fixed by deleting the semicolon near the '{' by :

p,
ul,   <------------ deleted this semicolon
{
    text-align: justify;
}

Temkit avatar Jan 27 '18 17:01 Temkit

Any news on that? With 1.7.0 stable it still occurs.

blackholegalaxy avatar Feb 17 '18 15:02 blackholegalaxy

This is also happening for me too. I can confirm downgrading @angular/cli to 1.6.6 fixes the problem.

If it helps in solving what is going on in 1.7 here is my environment info.

It is happening on both MacOS and the node:latest containers that I am using on GitLab in my CI pipeline.

.../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

KayoticSully avatar Feb 18 '18 05:02 KayoticSully

same issue with 1.7.0 stable

.../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

sgomanf avatar Feb 18 '18 14:02 sgomanf

Downgrading to 1.6.8 fixes the issue. It surely is a dependency upgrade in 1.7.0 which is more strict on css/scss way of writing. It's abnormal since style which was previously "compiled" and minified previously should not break the build since there was no change in these files.

There are several way of writing css, including breaking lines on some long properties. It should'nt break the build.

blackholegalaxy avatar Feb 18 '18 14:02 blackholegalaxy

As already mentioned, broken in 1.7.0 but working in 1.6.8 with the same error as @KayoticSully and @sgomanf.

In my case the error occurs in a third party SCSS file from the PrimeNG Ultima theme.

_data.scss.txt

If I reformat the file using VSCode the error in the production build goes away but the CSS produced does not look right ...

_data (reformatted in VScode).scss.txt

Using original _data.scss (CSS correct, compile error prod build).

image

Using reformatted _data.scss (CSS incorrect, compile OK prod build).

image

jamieathans avatar Feb 19 '18 01:02 jamieathans

I am also facing this issue.

Is there any solution for this?

ayyazzafar avatar Feb 19 '18 12:02 ayyazzafar

In my opinion, the way we write css, including "beautified" versions with multiple line breaks for better "looking code" should not impact the build success or fail.

blackholegalaxy avatar Feb 19 '18 14:02 blackholegalaxy

@blackholegalaxy I have too many css files in my project. Is there any way that I can find out that which file has such issue ? Or is there any way to troubleshoot this ?

ayyazzafar avatar Feb 19 '18 15:02 ayyazzafar

Downgrading to 1.6.8 did not solve my issue.

ayyazzafar avatar Feb 19 '18 15:02 ayyazzafar

I did not manage to find a way to detect faulty file. Solution by @MisterEffix console logs around 500 lines of 0, 1px and single liners like that. So it doesn't help determine which file/line is faulty.

blackholegalaxy avatar Feb 19 '18 15:02 blackholegalaxy

@blackholegalaxy, I have looked for a line at the end of these logs the first line that was "foundable" in my source files. My one was something like "0.2s margin ease-in" (a string easly foundable in my css).

It didn't point exactly to the problematic css property but the problem wasn't far away.

Hope it helps.

ghost avatar Feb 19 '18 15:02 ghost

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 that please fix this angular cli issue so that we can use latest versions.

I hope this would help.

ayyazzafar avatar Feb 19 '18 16:02 ayyazzafar

adding console.log(serializedBuffer) at node_modules/clean-css/lib/tokenizer/tokenizer.js

This worked for me. My stack trace was a little different and so I had to add this at a different line number, however, it was sufficient to help me identify the error in my CSS. It boiled down to the same issue @Knewtone was having -- an extra comma following the rule name.

jacobslusser avatar Feb 19 '18 18:02 jacobslusser