You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ng Serve stops responding to file changes when editing ts/html files using Visual Studio 2022 (17.8.0) #26437
So this is a super weird one. Debugging with @clydin, we were able to reproduce and open Visual Studio and VSCode next to each other on the same project. We were actually able to get two changes rebuilt in Visual Studio before it stops rebuilding. However VSCode can continue to edit the same project and changes are immediately applied.
We also confirmed that Visual Studio was writing to the file system correctly and that the file is byte-for-byte identical between the two editors. We were suspecting this might be an encoding or line ending issue, but we can safely rule both of those out.
We found a couple references to the fact that Visual Studio is unique in that it doesn't modify files directly. Instead it writes them to a temporary directory and then moves them to the actual location. This can be observed as different file system events for file watchers and seems to be a common problem. This is likely the root cause of the problem, however exactly where the fix should be is still unclear.
We also tried enabling polling, but this didn't help. The only workaround which solved the issue was to watch the project root directory entirely. As to why this solves the problem, I'm not entirely sure. Doing it is also a performance regression for Windows users not on Visual Studio.
We tried ng serve --verbose which lists out the file modifications detected to see exactly what event the project root picks up that is getting missed. However we only see modifications to the app.component.html file, nothing else. So we don't understand why this event requires watching the project root at all.
Obsolete workaround
WORKAROUND: You can force Angular CLI to watch the project root with the NG_BUILD_WATCH_ROOT environment variable.
For command prompt:
setNG_BUILD_WATCH_ROOT=1
ng serve
For PowerShell:
$env:NG_BUILD_WATCH_ROOT=1
ng serve
We'll need to do a little more investigation to figure out exactly what's going on here and what the proper fix is.
Just published v17.0.3 which updates Angular CLI to watch the project root by default. That should hopefully work around the problem automatically without requiring the environment variable.
We'll still want to do some more investigation here to find a more permanent fix.
Activity
dgp1130 commentedon Nov 21, 2023
So this is a super weird one. Debugging with @clydin, we were able to reproduce and open Visual Studio and VSCode next to each other on the same project. We were actually able to get two changes rebuilt in Visual Studio before it stops rebuilding. However VSCode can continue to edit the same project and changes are immediately applied.
We also confirmed that Visual Studio was writing to the file system correctly and that the file is byte-for-byte identical between the two editors. We were suspecting this might be an encoding or line ending issue, but we can safely rule both of those out.
We found a couple references to the fact that Visual Studio is unique in that it doesn't modify files directly. Instead it writes them to a temporary directory and then moves them to the actual location. This can be observed as different file system events for file watchers and seems to be a common problem. This is likely the root cause of the problem, however exactly where the fix should be is still unclear.
We also tried enabling polling, but this didn't help. The only workaround which solved the issue was to watch the project root directory entirely. As to why this solves the problem, I'm not entirely sure. Doing it is also a performance regression for Windows users not on Visual Studio.
We tried
ng serve --verbosewhich lists out the file modifications detected to see exactly what event the project root picks up that is getting missed. However we only see modifications to theapp.component.htmlfile, nothing else. So we don't understand why this event requires watching the project root at all.Obsolete workaround
WORKAROUND: You can force Angular CLI to watch the project root with the
NG_BUILD_WATCH_ROOTenvironment variable.For command prompt:
For PowerShell:
We'll need to do a little more investigation to figure out exactly what's going on here and what the proper fix is.
MichielNL83 commentedon Nov 21, 2023
Can confirm on my end that adding the 'NG_BUILD_WATCH_ROOT=1' environment variable indeed works as a workaround.
fix(@angular-devkit/build-angular): default to watching project root …
fix(@angular-devkit/build-angular): default to watching project root …
fix(@angular-devkit/build-angular): default to watching project root …
dgp1130 commentedon Nov 22, 2023
Just published v17.0.3 which updates Angular CLI to watch the project root by default. That should hopefully work around the problem automatically without requiring the environment variable.
We'll still want to do some more investigation here to find a more permanent fix.
fix(@angular-devkit/build-angular): improve file watching on Windows …
2 remaining items
fix(@angular-devkit/build-angular): improve file watching on Windows …
fix(@angular-devkit/build-angular): improve file watching on Windows …
fix(@angular-devkit/build-angular): improve file watching on Windows …
alan-agius4 commentedon Nov 23, 2023
Hi @MichielNL83,
Would you mind to verify if applying the changes in #26468 fixes the issue?
Steps to apply the update:
node_modules/@angular-devkit/build-angular/src/tools/esbuild/watcher.jswith https://gist.github.com/alan-agius4/f9a9c0a52f1b6b53895d3617e515dd97node_modules/@angular-devkit/build-angular/src/utils/environment-options.jswith https://gist.github.com/alan-agius4/200fe02b59519a1bb0f5338fb8bcc225MichielNL83 commentedon Nov 23, 2023
@alan-agius4 ,
Yes, these changes fix the issue.
alan-agius4 commentedon Nov 23, 2023
@MichielNL83, thanks for the checking and confirming that the proposed change fixes the issue for you. Much appreciated.
fix(@angular-devkit/build-angular): improve file watching on Windows …
fix(@angular-devkit/build-angular): improve file watching on Windows …
fix(@angular-devkit/build-angular): improve file watching on Windows …
fix(@angular-devkit/build-angular): improve file watching on Windows …
fix(@angular-devkit/build-angular): improve file watching on Windows …
fix(@angular-devkit/build-angular): improve file watching on Windows …
angular-automatic-lock-bot commentedon Dec 24, 2023
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.