Возникли проблемы с публикацией приложения React в iis - AggregateException и InvalidOperationException - PullRequest
0 голосов
/ 09 июля 2020

Я получаю сообщение об ошибке после того, как опубликовал свой веб-сайт на сервере и пытаюсь его открыть. Приложение создано в Visual Studio с использованием .core 3.1 - react.

Не уверен, что могло вызвать это, но я предполагаю, что оно должно что-то делать со сборкой скрипта внутри пакета. json file.

package. json:

  "scripts": {
    "start": "rimraf ./build && react-scripts start",
    "build": "react-scripts build",
    "production": "env-cmd -f .env.prod react-scripts build",
  },

startup.cs (я пробовал использовать и build, и production, но возникла та же проблема).

if (env.IsProduction())
{
      spa.UseReactDevelopmentServer(npmScript: "build");
}

И исключение:

AggregateException: One or more errors occurred. (One or more errors occurred. (The NPM script 'build' exited without indicating that the create-react-app server was listening for requests. The error output was: ))
System.Threading.Tasks.Task.ThrowIfExceptional(bool includeTaskCanceledExceptions)

InvalidOperationException: The NPM script 'build' exited without indicating that the create-react-app server was listening for requests. The error output was:
Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer.ReactDevelopmentServerMiddleware.StartCreateReactAppServerAsync(string sourcePath, string npmScriptName, ILogger logger)

AggregateExeption:

AggregateException: One or more errors occurred. (One or more errors occurred. (The NPM script 'build' exited without indicating that the create-react-app server was listening for requests. The error output was: ))
System.Threading.Tasks.Task.ThrowIfExceptional(bool includeTaskCanceledExceptions)
System.Threading.Tasks.Task<TResult>.GetResultCore(bool waitCompletionNotification)
System.Threading.Tasks.Task<TResult>.get_Result()
Microsoft.AspNetCore.SpaServices.Extensions.Util.TaskTimeoutExtensions.WithTimeout<T>(Task<T> task, TimeSpan timeoutDelay, string message)
Microsoft.AspNetCore.SpaServices.Extensions.Proxy.SpaProxy.PerformProxyRequest(HttpContext context, HttpClient httpClient, Task<Uri> baseUriTask, CancellationToken applicationStoppingToken, bool proxy404s)
Microsoft.AspNetCore.Builder.SpaProxyingExtensions+<>c__DisplayClass2_0+<<UseProxyToSpaDevelopmentServer>b__0>d.MoveNext()
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Show raw exception details
System.AggregateException: One or more errors occurred. (One or more errors occurred. (The NPM script 'build' exited without indicating that the create-react-app server was listening for requests. The error output was: ))
 ---> System.AggregateException: One or more errors occurred. (The NPM script 'build' exited without indicating that the create-react-app server was listening for requests. The error output was: )
 ---> System.InvalidOperationException: The NPM script 'build' exited without indicating that the create-react-app server was listening for requests. The error output was: 
 ---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.
   at Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer.ReactDevelopmentServerMiddleware.StartCreateReactAppServerAsync(String sourcePath, String npmScriptName, ILogger logger)
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer.ReactDevelopmentServerMiddleware.StartCreateReactAppServerAsync(String sourcePath, String npmScriptName, ILogger logger)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer.ReactDevelopmentServerMiddleware.<>c.<Attach>b__2_0(Task`1 task)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__274_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   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)

InvalidOperationException:

InvalidOperationException: The NPM script 'build' exited without indicating that the create-react-app server was listening for requests. The error output was:
Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer.ReactDevelopmentServerMiddleware.StartCreateReactAppServerAsync(string sourcePath, string npmScriptName, ILogger logger)

Show raw exception details
System.InvalidOperationException: The NPM script 'build' exited without indicating that the create-react-app server was listening for requests. The error output was: 
 ---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.
   at Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer.ReactDevelopmentServerMiddleware.StartCreateReactAppServerAsync(String sourcePath, String npmScriptName, ILogger logger)
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer.ReactDevelopmentServerMiddleware.StartCreateReactAppServerAsync(String sourcePath, String npmScriptName, ILogger logger)

Поскольку я как бы новичок в React, если есть что-нибудь, что я мог бы сделать для отладки этой или любой другой информации, которая могла бы помочь, пожалуйста, дайте мне знать.

1 Ответ

1 голос
/ 10 июля 2020

Подкаталог ClientApp является стандартным React Application на основе шаблона Create-React-App. Следовательно, это зависит от NPM command. Попробуйте обновить версию Nodejs, загрузив ее напрямую в официальном документе NodeJs. https://nodejs.org/en/download/ При определенных обстоятельствах мы также должны очистить установленные глобальные модули. Пожалуйста, проверьте эту ссылку для получения более подробной информации. https://www.reddit.com/r/dotnet/comments/bcd221/using_my_own_packagejson_for_react_causes_aspnet/

...