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

`ng serve` automatically rebuilds

Open sarunint opened this issue 8 years ago • 12 comments

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)

sarunint avatar May 21 '18 03:05 sarunint

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.

filipesilva avatar May 21 '18 10:05 filipesilva

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.

sarunint avatar May 21 '18 10:05 sarunint

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

image

sarunint avatar May 22 '18 07:05 sarunint

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?

filipesilva avatar May 22 '18 08:05 filipesilva

Will try soon! Thanks for your help.

sarunint avatar May 22 '18 08:05 sarunint

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

sarunint avatar Sep 22 '18 22:09 sarunint

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

sarunint avatar Sep 22 '18 22:09 sarunint

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!!!!!

argygkou avatar Nov 01 '18 09:11 argygkou

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

jeffgammon avatar Nov 28 '18 16:11 jeffgammon

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

jeffgammon avatar Nov 30 '18 16:11 jeffgammon

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!

ykamal avatar Jul 23 '19 13:07 ykamal

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.