Skip to content

Intermittent compilation error when using LESS loader #14805

@seaBubble

Description

@seaBubble

🐞 Bug report

Command (mark with an x)

- [ ] new
- [ ] build
- [x] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

No

Description

In an Angular project using LESS, if I serve the app, sometimes an error is thrown while compiling the LESS code. If I run ng serve again, sometimes it goes away, sometimes I need to serve it again.

🔬 Minimal Reproduction

ng serve
throws, sometimes only,
an error described below
always pointing at the same LESS file, which contains


@types: ~'type1' ~'type2';
.for(@i, @n) {
  .-each(@i);
}
.for(@n) when (isnumber(@n)) {
  .for(1, @n);
}

.for(@i, @n) when not (@i = @n) {
  .for((@i + (@n - @i) / abs(@n - @i)), @n);
}

.for(@array) when (default()) {
  .for-impl_(length(@array));
}

.for-impl_(@i) when (@i > 1) {
  .for-impl_((@i - 1));
}

.for-impl_(@i) {
  .-each(extract(@array, @i));
}
.mixin-test() {
  .for(@types);
  .-each(@name) {
    .define(@name);
    .status-icon-@{name}& {
      color: @@color;
    }
  }
}


.mixin-test(); 

🔥 Exception or Error



Module build failed (from ./node_modules/less-loader/dist/cjs.js):

 


Cannot read property 'substring' of undefined

      in undefined (line undefined, column undefined)

TypeError: Cannot read property 'substring' of undefined

    at SourceMapOutput.add /node_modules/less/lib/less/source-map-output.js:72:39)

    at Element.genCSS (/node_modules/less/lib/less/tree/element.js:46:12)

    at Selector.genCSS (/node_modules/less/lib/less/tree/selector.js:125:17)

    at Ruleset.genCSS (/node_modules/less/lib/less/tree/ruleset.js:484:21)

    at Ruleset.genCSS (/node_modules/less/lib/less/tree/ruleset.js:508:18)

    at SourceMapOutput.toCSS (/node_modules/less/lib/less/source-map-output.js:123:24)

    at SourceMapBuilder.toCSS (/node_modules/less/lib/less/source-map-builder.js:23:35)

    at ParseTree.toCSS (/node_modules/less/lib/less/parse-tree.js:33:47)

    at /node_modules/less/lib/less/render.js:35:40

    at /node_modules/less/lib/less/parse.js:86:21

    at ImportVisitor.finish [as _finish] (/node_modules/less/lib/less/parser/parser.js:240:28)

    at ImportVisitor._onSequencerEmpty (/node_modules/less/lib/less/visitors/import-visitor.js:36:14)

    at ImportSequencer.tryRun (/node_modules/less/lib/less/visitors/import-sequencer.js:50:14)

    at /node_modules/less/lib/less/visitors/import-sequencer.js:19:25

    at fileParsedFunc (/node_modules/less/lib/less/import-manager.js:63:17)

    at loadFileCallback (/node_modules/less/lib/less/import-manager.js:133:21)

    at process._tickCallback (internal/process/next_tick.js:68:7)

 @ ./src/app/test.component.ts 44:21-65

 @ ./src/app/test.module.ts

@ ./src/app/app.module.ts

 @ ./src/main.ts

 @ multi (webpack)-dev-server/client?http://0.0.0.0:0/sockjs-node ./src/main.ts

 

ERROR in ./src/app/test.component.less

Module build failed (from ./node_modules/less-loader/dist/cjs.js):

 

 

Cannot read property 'substring' of undefined

      in undefined (line undefined, column undefined)

TypeError: Cannot read property 'substring' of undefined

    at SourceMapOutput.add (/node_modules/less/lib/less/source-map-output.js:72:39)

    at Element.genCSS (/node_modules/less/lib/less/tree/element.js:46:12)

    at Selector.genCSS (/node_modules/less/lib/less/tree/selector.js:125:17)

    at Ruleset.genCSS (/node_modules/less/lib/less/tree/ruleset.js:484:21)

    at Ruleset.genCSS (/node_modules/less/lib/less/tree/ruleset.js:508:18)

    at SourceMapOutput.toCSS (/node_modules/less/lib/less/source-map-output.js:123:24)

    at SourceMapBuilder.toCSS (/node_modules/less/lib/less/source-map-builder.js:23:35)

    at ParseTree.toCSS (/node_modules/less/lib/less/parse-tree.js:33:47)

    at /node_modules/less/lib/less/render.js:35:40

    at /node_modules/less/lib/less/parse.js:86:21

    at ImportVisitor.finish [as _finish] (/node_modules/less/lib/less/parser/parser.js:240:28)

    at ImportVisitor._onSequencerEmpty (/node_modules/less/lib/less/visitors/import-visitor.js:36:14)

    at ImportSequencer.tryRun (/node_modules/less/lib/less/visitors/import-sequencer.js:50:14)

    at /node_modules/less/lib/less/visitors/import-sequencer.js:19:25

    at fileParsedFunc (/node_modules/less/lib/less/import-manager.js:63:17)

    at loadFileCallback (/node_modules/less/lib/less/import-manager.js:133:21)

    at process._tickCallback (internal/process/next_tick.js:68:7)

 @ ./src/app/test.component.ts 44:21-65

 @ ./src/app/test.module.ts

 @ ./src/app/app.module.ts

 @ ./src/main.ts

 @ multi (webpack)-dev-server/client?http://0.0.0.0:0/sockjs-node ./src/main.ts

ℹ 「wdm」: Failed to compile.

🌍 Your Environment


Angular CLI: 7.3.8
Node: 10.5.0
OS: darwin x64
Angular: 7.2.14
... animations, common, compiler, core, forms, http
... platform-browser, platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.13.8
@angular-devkit/build-angular     0.13.8
@angular-devkit/build-optimizer   0.13.8
@angular-devkit/build-webpack     0.13.8
@angular-devkit/core              7.3.8
@angular-devkit/schematics        7.3.8
@angular/cdk                      7.3.7
@angular/cli                      7.3.8
@angular/compiler-cli             7.2.3
@angular/language-service         7.2.3
@angular/material                 7.3.7
@ngtools/webpack                  7.3.8
@schematics/angular               7.3.8
@schematics/update                0.13.8
rxjs                              6.5.2
typescript                        3.2.4
webpack                           4.29.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs: repro stepsWe cannot reproduce the issue with the information given

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions