-
Notifications
You must be signed in to change notification settings - Fork 10.3k
.NET Core 3.0 + Angular 9 cli application called via the SpaServices extensions hangs in common configuration #17277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I also have this issue, but don't want to have to re-enable |
Actually, I don't think it's quite as simple as that - when I run I think the problem is that the message will only show on the first log output from the CLI (https://github.com/angular/angular-cli/blob/2c0efd834b08ac5ea166d88c0ff57cc35df19421/packages/angular_devkit/build_angular/src/dev-server/index.ts#L361) and this often takes longer than the five second default timeout after which .NET assumes that the CLI has died (https://github.com/aspnet/AspNetCore/blob/master/src/Middleware/SpaServices.Extensions/src/AngularCli/AngularCliMiddleware.cs#L22). |
I am using .NET Core 3.1 and am encountering the same issue using I have zero clue as to why the following workaround works, but I consistently get the expected behavior if I add any statement that outputs to stdout prior to EDIT: Adding environment info:
|
@elianora I spent some time digging around today and found this bug: #6146 Basically, the wrapper around Could you check that you're referencing the latest version of the |
I am currently referencing |
I've made a shamelessly hacky workaround which will do for now. Basically, I wrap the call to the Angular CLI in another Node script, and spoof the "open your browser on" message so that dotnet notices it. You can try the workaround yourself:
|
This line is Windows-specific, the Linux equivalent would be something along the lines of (but possibly not exactly)
|
I run into no issues just using |
Do you still have dotnet randomly choosing a CLI port when you do that? |
I do, yes. |
@elianora suggestion of modifying the BTW, can't see how it would matter but I did notice a subtle difference in how the Angular CLI outputs build info between Angular 8 and 9. Specifically, the Date and Hash information comes after the chunk information in Angular 9, where as it is the first line in Angular 8.
Of course the actual string the AngularCliMiddleware is searching for: "open your browser on" is still being emitted by the angular_devkit package (Line 303). |
The I don't fully get why it fixes it though... EDIT: it seems that when I add the |
|
But as verbose mode extremely pollutes the console, it would be better to detect readiness by a background HTTP GET instead of parsing the console output. |
Due to a dependency, I'm unable to upgrade my .NET Core 2.2 app to 3 yet, so when I upgraded to Angular 9 I ran into this issue as well. The echo solution saved me; thank you @elianora ! Side note: I don't have progress set to false. It is true and I still ran into this issue, so I don't know that that's a factor here. |
Echo solution works sometimes. Some other times, it just hangs after logging the chunks without printing this message:
|
I encounter the same issue, and the "echo" workaround works for me (even if I don't understand why).
With Angular 9: the line 404s will fallback to //index.html is not there anymore
|
Still waiting on a fix for this. The echo solution doesn't work for me, but the node does. It's pretty ugly. Not sure if angular needs to change the way they emit to the console or the spa service extension needs to change the way it listens. For anyone wanting to use Angular 9 with a netcore3 app, i would recommend going back to angular 8 until this gets resolved. Otherwise the node hack from @benelliott worked for me |
What worked for me was changing "ng serve" to "ng serve --host 0.0.0.0" in package.json "start" |
Hello, I had the same problem and I performed several tests on different projects and simply saving some change in a file inside the ClientApp folder, it makes angular recompile and then VS2019 / VSCode recognizes the node server, without changing any configuration. I comment this in case it helps anyone. I also tested in the solution of the repo miguellira/Angular9CliTemplateBug with VS 2019 Community and VS Code and works. |
this worked for me |
The above solutions did not work for me but this did
|
Every few days both new and senior .NET developers stumble upon this bug and post a comment to share their frustration. Although I can sympathize, as the OP it surprises me since I thought I did a decent job describing various workarounds including the simplest one that has worked for me with every release of update the Lately, however, some of the posts have expressed concerns of back porting the "fix" to .NET 3.x so I wanted to share my thoughts:
Hope that clears up the back porting concern. I will also update the original post to better describe the simplest workaround. |
i am getting this error is the error related to this issue?
or should i just keep using angular 8? |
@hoksource you can just remove that line. that issue is not related to this one. when the angular cli upgrades your app to v9 it dumps that line into main.ts in a subjectively dumb way. it's helpful to have it there for those using universal (if i remember correctly), but it's problematic for those of us not using universal. |
FWIW, I was able to fix this in my project by forking my own copy of the Microsoft.AspNetCore.SpaServices.Extensions project (from the 2.1 release branch), and then dropping in the internal EventedStreamReader class from the .net 5 release branch. This seems to solve the problem where it never sees the line saying "open your browser...". |
Looks that aspnet team no longer cares about the Angular template... net5 still installs angular 8 even tho angular 11 is almost out. |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
This also affected me but the workaround worked with .NET Core 3.1 and Angular 10.1. |
I recently upgraded from Angular 10.1.1 to 10.2.3, and this problem inexplicably got a lot more frequent, to the point of being unusable. This is with the echo and progress solutions in place. So I tried upgraded my Microsoft.AspNetCore.* NuGet packages to 3.1.10, and I also tried upgrading Angular to 11.0.4. With those upgrades done, I am unable to get any solution mentioned above to work aside from "Run "ng serve" independently" from the Docs. That is to say, for me, this problem now has no known solution other than completely abandoning the automatic background Ng CLI process, as it is now non-functional 100% of the time. I can't explain why or who it suddenly broke except for the upgrade from Angular 10.1.1 to 10.2.3. It's unthinkable to me that a problem this bad has been ignored by MSFT for over a year now. |
I upgraded to .Net 5 and it got way better. With 3.1 it was unusable. |
I have this bug only on debugging (F5) on .NET 3.1+Angular 11.0.5.only work after I try for 9 or 10 times,too hard to debug... |
The only workaround that worked for us (.NET 3.1.11 + Angular 11.0.5): |
Giving timeout exception for .Net 5.0 and angular 11.0.4 TimeoutException: The Angular CLI process did not start listening for requests within the timeout period of 0 seconds. Check the log output for error information. Here are the things I tried none of them worked.
https://developercommunity.visualstudio.com/t/Angular-1104--Net-50-Giving-Timeout/1393855 |
@heart2friend as a last try you can always start the angular process in a different terminal and switch the spa service to running on developer port. |
This workaround fixed it in my case: |
@heart2friend updating from .Net Core 3.1 to .Net5 fixed it for me. |
Thank you @svrooij it worked. This shouldn't be the ideal solution but it's working is lot more for me. For those who are struggling with same problem here is the interim solution
app.UseSpa(spa =>
This works like a charm! |
@benelliott Thanks, your fix is the only solution that works for me. There is one issue though. The Node.js process is kept alive after closing the debug session in VS Code. If I restart a few times I soon run out of memory and the CPU usage skyrockets. Is there a way to kill the Node.js process? Right now I'm debating whether to give up and just start the .Net part and frontend parts separately. |
Has there been any progress on this? I have several developers with exactly this problem and all the workarounds are no longer working. This does seem to have become worse with Angular 12, where the compilation time has increased. I am now resorting to running the angular client separately before running the hosting application in the IDE. |
Our fix was to have this script in package.json
And then a file ngserve.cmd with the following:
We have no issues now, but an actual fix from MS would of course be better. |
Closing this as we've changed the approach how the SPA project templates work now. You can find more details about this in the issue tracking that work: #27887 |
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
Running a
.NET Core 3.0
+Angular 9 cli
(version 9.0.0-rc.2 as of this post) with the angular cli build optionprogress
set tofalse
will hang until theStartupTimeout
expires (default: 120 seconds)To Reproduce
I created a repo with a bare bones
.NET Core 3.0
+Angular 9 cli
application to demo the bug. Simply clone,npm build
the ClientApp folder, anddotnet run
. Or you can follow the steps below to do this from scratch:.NET Core 3.0
installeddotnet new angular -n HelloWorld
ClientApp
folder and install the Typescript helper functions required for Angular 9 by typing:npm install tslib@latest
ng update @angular/core @angular/cli --next
progress
build option in theangular.json
file is set to falsedotnet run
https://localhost:5001
The application will hang and eventually timeout.
Further technical details
This appears to be caused by a change in how
ng serve
outputs to the console in the new Angular 9 CLI. TheAngularCliMiddleware
makes aWaitForMatch()
method call against the standard output to signify when the Angular assets have been generated and the web server is ready to receive requests (Line 84). However, unless theprogress
option is set to true in theangular.json
file you never see the expected line.UPDATE: Updated to .NET Core 3.1 and Angular 9.0.0-rc.5. Same issue. New, simpler workaround is to modify your
npm start
script to perform a simpleecho
prior tong serve
(see comment below)UPDATE (6/5/2020): Lots of recent comments so I figured I'd share exactly what has worked for me with every release of
.NET
andAngular
since my original post. Update yourpackage.json
like so:The text was updated successfully, but these errors were encountered: