我读的书从一开始就具有版本9(ASP.NET Core 3和Angular 9-第三版),并且还使用了angular模板。我已经安装了vs 2019的最新Visual Studio更新。
Angular项目的模板的版本为8。我读的书的版本为9。因此,我尝试更新我的angular版本。
ng update
给了我
@angular/cli 8.3.14 -> 9.0.3 ng update @angular/cli
@angular/core 8.2.12 -> 9.0.3 ng update @angular/core
@nguniversal/aspnetcore-engine 8.1.1 -> 8.2.6 ng update @nguniversal/aspnetcore-engine
我更新了cli和core。但是当我尝试更新第三个软件包时,我得到了:
C:\Users\user\Test\ClientApp>ng update @nguniversal/aspnetcore-engine
Using package manager: 'npm'
Collecting installed dependencies...
Found 39 dependencies.
Package '@nguniversal/aspnetcore-engine' is not a dependency.
我仍然尝试运行该应用程序,并且得到HTML
Cannot GET /
或具有以下内容的例外页面:
System.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.
at Microsoft.AspNetCore.SpaServices.Extensions.Util.TaskTimeoutExtensions.WithTimeout[T](Task`1 task, TimeSpan timeoutDelay, String message)
at Microsoft.AspNetCore.SpaServices.Extensions.Proxy.SpaProxy.PerformProxyRequest(HttpContext context, HttpClient httpClient, Task`1 baseUriTask, CancellationToken applicationStoppingToken, Boolean proxy404s)
at Microsoft.AspNetCore.Builder.SpaProxyingExtensions.<>c__DisplayClass2_0.<<UseProxyToSpaDevelopmentServer>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
答案 0 :(得分:0)
也许有点晚了,但这也许对其他人有帮助。我面临着完全相同的问题。 要使其工作,请在package.json中进行此操作。
更改
"scripts":{
...
"start": "ng serve"
...
}
"scripts":{
...
"start": "echo Starting... && ng serve"
...
}
此内容摘自Smatusan的评论。这就是它起作用的explanation。
“由于此问题经常发生,是因为ng服务的初始生成时间超过了.NET SPA服务的编程超时窗口,因此,通过给予回显,.NET SPA服务会接收到一些数据并认为已连接。 ” -mikejunt。
答案 1 :(得分:0)
当我将 angular 版本升级到 11 并且仍在运行 .net core 3.1 时,我遇到了类似的问题。
我是如何解决的:
完成 Angular 更新(确保节点模块也是最新的) 安装 .Net 核心 5.0 右键解决方案->属性->应用程序:目标框架下拉列表(更改为最近安装的5.0) 保存更改 管理 Nuget 包 -> 将 Microsoft.AspNetCore.SpaServices.Extensions 更新到版本 5+
然后我就可以正常启动调试会话了。
答案 2 :(得分:0)
将 Angular 从 v8 升级到 v9 时,'ng update' 在 main.ts 中添加这一行
export { renderModule, renderModuleFactory } from '@angular/platform-server';
把它去掉,上面的错误就没有了,检查这个link