Angular-cli: `ng serve` automatically rebuilds

Created on 21 May 2018  路  12Comments  路  Source: angular/angular-cli

Versions

Angular CLI: 6.0.3
Node: 10.0.0
OS: linux x64
Angular: 6.0.2
... common, compiler, compiler-cli, core, forms, http
... platform-browser, platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.3
@angular-devkit/build-angular     0.6.3
@angular-devkit/build-optimizer   0.6.3
@angular-devkit/core              0.6.3
@angular-devkit/schematics        0.6.3
@angular/cli                      6.0.3
@ngtools/webpack                  6.0.3
@schematics/angular               0.6.3
@schematics/update                0.6.3
rxjs                              6.1.0
typescript                        2.7.2
webpack                           4.8.3

Repro steps

  • run ng serve --aot. (Not tested with non-AOT yet)

Observed behavior

Webpack recompiles many times without file changes, which leads to multiple browser refresh. Notice that the hash stays the same.
image

Desired behavior

Webpack rebuilds only on file changes.

Mention any other details that might be useful (optional)

devkibuild-angular help wanted more info

All 12 comments

Heya, I don't know what causes this but I have seen it under some circumstances or another over the years. It doesn't happen on all machines. At some point I always saw it happening on CircleCI docker containers but it doesn't anymore.

Can you tell me more about your environment please?

A workaround is to use --poll 1000 for now.

If you want to try and debug it, you can edit node_modules/@ngtools/webpack/src/angular_compiler_plugin.js and replace

compiler.hooks.invalid.tap('angular-compiler', () => this._firstRun = false);

with

compiler.hooks.invalid.tap('angular-compiler', (changed) => {
  console.log('### CHANGED', changed);
  this._firstRun = false
});

This might give you an idea of what files webpack thinks have changed. If there's a pattern maybe we can do something about it.

Strange, this issue started to appear since v6. Before that, I don't have any "auto-rebuild".

For the record, my system is Windows 10 but running node in WSL.

Will try the debugging as soon as I get home.

Hi @filipesilva, I did what you asked me to do, and here's the result!

image

Well, this is unfortunate.... it looks like random files are being touched, but not modified, all the time. I'm not really sure what we can do about that.

Does this happen if you run outside WSL?

Will try soon! Thanks for your help.

@filipesilva long time no see!

Recently, no "auto-rebuilds" has occurred yet. (Yes, in WSL.) I will assume that this issue is resolved.

Thanks for you help anyway.

I may try downgrade the CLI to see which version resolves this problem though.

I have the same problem from version 5 to version 7 that I updated two days ago. Every time I click on a file or a folder in vs code, angular cli rebuilds.
I'm using Angular v7 with Nx v7.
Can anyone help? it's very frustrating!!!!!

I have the same auto-rebuild problem also. Files that have not been edited cause a rebuild. Also super frustrated.
Windows 10
Angular 6.0.3
node v8.11.2
I do not use WSL.
I have run ng serve from from both git's bash shell and Windows Command Prompt, and rebuild happens in both.

I edited node_modules/@ngtools/webpack/src/angular_compiler_plugin.js as suggested by @filipesilva and captured a similar log as @sarunint. I see no pattern to the touched files. Sometimes they are my files, sometimes they are other's files down in node_modules. I can sometimes get them to "touch" by simply listing files in some directory from a bash shell; i.e., cd to some component folder in the project and then ls will cause the rebuild. Opening a file in VS Code sometimes also triggers the rebuild.

I welcome any other suggestions or workarounds.

cli_rebuilds

The --poll 1000 workaround appears to be working for me as well. 2 days and no unexpected rebuilds. Thank you @filipesilva

The --poll 1000 workaround appears to be working for me as well. 2 days and no unexpected rebuilds. Thank you @filipesilva

Thanks! This has fixed the issue for me too!

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vinodbhargava picture vinodbhargava  路  214Comments

ankeshdave picture ankeshdave  路  161Comments

adwd picture adwd  路  173Comments

DanielStep picture DanielStep  路  184Comments

jdcrecur picture jdcrecur  路  99Comments