我正在尝试启动.NET Core 2 / Angular 6 SPA。我使用“dotnet new angular”创建了一个Angular 5应用程序,然后使用angular.io中的this guide进行升级。完成升级后,我尝试使用“dotnet run”运行应用程序,然后出现错误的错误页面:
处理请求时发生未处理的异常。
AggregateException:发生了一个或多个错误。 (一个或多个错误 发生了。 (NPM脚本'开始'退出但没有指出 Angular CLI正在侦听请求。错误输出为:未知 选项:'--extractCss'
InvalidOperationException:NPM脚本'start'退出,但未指示Angular CLI正在侦听请求。错误输出为:未知选项:' - extraCss'
想想也许我在升级过程中错过了一步,我第二次尝试并得到了同样的错误。
以下是我在创建应用后采取的步骤:
npm install -g @angular/cli
npm install @angular/cli
ng update @angular/cli
ng update @angular/core
npm install --save @angular/material @angular/cdk @angular/animations hammerjs
npm install -g rxjs-tslint
rxjs-5-to-6-migrate -p src/tsconfig.app.json
我在Windows 10(1703)Enterprise上运行Node版本9.4.0和.Net Core 2.1.200。
有关如何解决此问题的任何想法?这是一个完整的堆栈跟踪:
---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.SpaServices.AngularCli.AngularCliMiddleware.<StartAngularCliServerAsync>d__3.MoveNext()
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.SpaServices.AngularCli.AngularCliMiddleware.<StartAngularCliServerAsync>d__3.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at Microsoft.AspNetCore.SpaServices.AngularCli.AngularCliMiddleware.<>c.<Attach>b__2_0(Task`1 task)
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at Microsoft.AspNetCore.SpaServices.Extensions.Util.TaskTimeoutExtensions.<WithTimeout>d__1`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.SpaServices.Extensions.Proxy.SpaProxy.<PerformProxyRequest>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
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 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()
---> (Inner Exception #0) System.AggregateException: One or more errors occurred. (The NPM script 'start' exited without indicating that the Angular CLI was listening for requests. The error output was: Unknown option: '--extractCss'
) ---> System.InvalidOperationException: The NPM script 'start' exited without indicating that the Angular CLI was listening for requests. The error output was: Unknown option: '--extractCss'
---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.SpaServices.AngularCli.AngularCliMiddleware.<StartAngularCliServerAsync>d__3.MoveNext()
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.SpaServices.AngularCli.AngularCliMiddleware.<StartAngularCliServerAsync>d__3.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at Microsoft.AspNetCore.SpaServices.AngularCli.AngularCliMiddleware.<>c.<Attach>b__2_0(Task`1 task)
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
---> (Inner Exception #0) System.InvalidOperationException: The NPM script 'start' exited without indicating that the Angular CLI was listening for requests. The error output was: Unknown option: '--extractCss'
---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.SpaServices.AngularCli.AngularCliMiddleware.<StartAngularCliServerAsync>d__3.MoveNext()
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.SpaServices.AngularCli.AngularCliMiddleware.<StartAngularCliServerAsync>d__3.MoveNext()<---
<---
答案 0 :(得分:33)
对我而言,以下问题已解决:https://github.com/angular/angular-cli/issues/10666
此外,您还需要编辑package.json文件并从start和build属性中删除--extractCss参数。 从:
"scripts": {
"ng": "ng",
"start": "ng serve --extract-css",
"build": "ng build --extract-css",
为:
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
答案 1 :(得分:9)
问题也困扰了我几天。现在终于可以解决了。显然,Visual Studio会尝试与ASP.Net核心进程一起自动为我们启动Angular CLI服务器。对于此实例,它失败了。
因此,根据Microsoft Doc here,我们可以手动启动Angular CLI服务器。
导航到“ ClientApp”文件夹,然后发出:
ng服务
从控制台启动服务器。
在“ Startup.cs”文件中,替换
spa.UseAngularCliServer(..)
使用
spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");
这样,您可以继续调试应用程序。
答案 2 :(得分:9)
尝试执行以下操作
对我有用
答案 3 :(得分:2)
如果上述解决方案不起作用,您可以尝试以下对我有用的方法。
方案:将运行中的VS 2017解决方案:核心Web API和angular spa项目转移到新安装的PC;给了我上面的错误。
解决方案:通过Visual Studio安装程序,用于Windows的node.js(https://nodejs.org/en/download/)和IIS所需的Windows功能安装了node.js工作负载之后;我回到了正轨。
主要安装是用于Visual Studio和Windows(包括npm)的node.js,必须同时安装它们才能正常工作。可能是命令提示符的路径配置。...
答案 4 :(得分:1)
Joe和Jays解决方案均有效。要使用默认模板配置而不更改代码,您只需要按照上述Jay的说明为Windows安装node.js,然后重新启动VS。 https://nodejs.org/en/download/
关于使用vs和vscode创建,配置和部署Core Angular项目的出色教程。还包括IIS安装程序。 https://www.codeproject.com/Articles/1250961/Deploying-an-Angular-Application-with-ASP-NET-Core
答案 5 :(得分:0)
就我而言,我已经从Azure网络应用程序中删除了以下应用程序设置,并且站点开始工作。
键:ASPNETCORE_ENVIRONMENT 价值:发展
花了几天时间找出问题所在:)
答案 6 :(得分:0)
我试图让GitHub项目从头开始工作。这些是我要做的事情:
dotnet new angular -o "C:\Users\me\OneDrive\Documents\Visual Studio 2017\Projects\myproject\myproject-dev\myproject-client-app" --force
npm install -g @angular/cli
npm build fix
npm run ng
npm start
ng start --extract-css
(我实际上不需要输入最后一个命令,因为npm start
为我的项目启动了该命令,但不一定总是这样...)
在“ Startup.cs”文件中,替换
spa.UseAngularCliServer(..)
使用
spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");
然后像通常开始调试应用程序一样, F5 启动ASP .NET Core项目。
所有这些之后,项目应该运行。
答案 7 :(得分:0)
VS 2019-通过导航到ClientApp文件夹并运行npm install
解决了错误。确保您已将npm
与Angular Cli一起安装在系统上。如果在安装Angular Cli时遇到问题,可以在package.json文件中将脚本从ng serve
更改为npm run start
。
答案 8 :(得分:0)
如果您使用 nvm 安装了多个 Node 版本。
你可以在终端cd进入项目根目录并执行
<块引用>nvm 使用 x.x.x
这解决了我的问题
答案 9 :(得分:0)
帮帮我。
2)从官网为你的操作系统安装node.js;