简体   繁体   English

带有React的ASP.NET Core 2.2 InvalidOperationException:无法启动'npm'

[英]ASP.NET Core 2.2 with React InvalidOperationException: Failed to start 'npm'

I've made a website in ASP.NET COre 2.2 with React+Redux. 我使用React + Redux在ASP.NET COre 2.2中创建了一个网站。

Locally in VS2019 works fine, but when I've moved to IIS10, where there is another ASP.NET Core WebAPI application that is correctly run, I get the error: 在VS2019本地工作正常,但当我转移到IIS10,其中有另一个正确运行的ASP.NET Core WebAPI应用程序,我收到错误:

InvalidOperationException: Failed to start 'npm' InvalidOperationException:无法启动'npm'

NodeJs is installed, and saved in C:\\Program Files\\NodeJs. NodeJ已安装,并保存在C:\\ Program Files \\ NodeJs中。 If I run npm -v I correctly get the version. 如果我运行npm -v我正确得到版本。

The application pool of the website is currently running with the identity Local System 该网站的应用程序池当前正在运行身份Local System

The Environment Variable is correctly set the right path, and even the error message can see it: 环境变量正确设置正确的路径,甚至错误消息都可以看到它:

[1] Ensure that 'npm' is installed and can be found in one of the PATH directories. [1]确保已安装'npm',并且可以在其中一个PATH目录中找到。 Current PATH enviroment variable is: C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\dotnet\\;C:\\Program Files (x86)\\dotnet\\; 当前PATH环境变量是:C:\\ Windows \\ system32; C:\\ Windows; C:\\ Windows \\ System32 \\ Wbem; C:\\ Windows \\ System32 \\ WindowsPowerShell \\ v1.0 \\; C:\\ Program Files \\ dotnet \\; C:\\ Program Files(x86)\\ dotnet \\; C:\\Program Files\\nodejs\\; C:\\ Program Files \\ nodejs \\; C:\\Windows\\system32\\config\\systemprofile\\AppData\\Local\\Microsoft\\WindowsApps Make sure the executable is in one of those directories, or update your PATH. C:\\ Windows \\ system32 \\ config \\ systemprofile \\ AppData \\ Local \\ Microsoft \\ WindowsApps确保可执行文件位于其中一个目录中,或更新PATH。

The stack is: 堆栈是:

System.AggregateException: Se han producido uno o varios errores. ---> System.AggregateException: Se han producido uno o varios errores. ---> System.InvalidOperationException: Failed to start 'npm'. To resolve this:.

[1] Ensure that 'npm' is installed and can be found in one of the PATH directories.
    Current PATH enviroment variable is: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\dotnet\;C:\Program Files (x86)\dotnet\;C:\Program Files\nodejs\;C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps
    Make sure the executable is in one of those directories, or update your PATH.

[2] See the InnerException for further details of the cause. ---> System.ComponentModel.Win32Exception: El nombre del directorio no es válido
   en System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   en System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   en Microsoft.AspNetCore.NodeServices.Npm.NpmScriptRunner.LaunchNodeProcess(ProcessStartInfo startInfo)
   --- Fin del seguimiento de la pila de la excepción interna ---
   en Microsoft.AspNetCore.NodeServices.Npm.NpmScriptRunner.LaunchNodeProcess(ProcessStartInfo startInfo)
   en Microsoft.AspNetCore.NodeServices.Npm.NpmScriptRunner..ctor(String workingDirectory, String scriptName, String arguments, IDictionary`2 envVars)
   en Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer.ReactDevelopmentServerMiddleware.<StartCreateReactAppServerAsync>d__3.MoveNext()
   --- Fin del seguimiento de la pila de la excepción interna ---
   en System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   en System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   en Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer.ReactDevelopmentServerMiddleware.<>c.<Attach>b__2_0(Task`1 task)
   en System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   en System.Threading.Tasks.Task.Execute()
   --- Fin del seguimiento de la pila de la excepción interna ---
   en System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   en Microsoft.AspNetCore.SpaServices.Extensions.Util.TaskTimeoutExtensions.<WithTimeout>d__1`1.MoveNext()
--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---
   en System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   en Microsoft.AspNetCore.SpaServices.Extensions.Proxy.SpaProxy.<PerformProxyRequest>d__4.MoveNext()
--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---
   en System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   en Microsoft.AspNetCore.Builder.SpaProxyingExtensions.<>c__DisplayClass2_0.<<UseProxyToSpaDevelopmentServer>b__0>d.MoveNext()
--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---
   en System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   en Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---
   en System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   en Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.<Invoke>d__7.MoveNext()
--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---
   en System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   en Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()
---> (Nº de excepción interna 0) System.AggregateException: Se han producido uno o varios errores. ---> System.InvalidOperationException: Failed to start 'npm'.

How can I fix it? 我该如何解决? I don't know what else to do... 我不知道还能做什么......

This error related to npm cant located so you need to check your enviroment variable like this. 此错误与npm cant相关,因此您需要检查您的环境变量。 Make sure when you go into nodejs folder you will npm file like this 确保当你进入nodejs文件夹时,你会像这样npm文件

在此输入图像描述

So check in system variable 所以检查系统变量

在此输入图像描述

and in user variable 在用户变量中

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM