Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to start 'npm': Ensure that 'npm' is installed and can be found

In Visual Studio 2019 v16.4.1 when attempting to run a ASP.NET Core Web Application with React installed I get an error in the loading webpage:

Failed to start 'npm': Ensure that 'npm' is installed and can be found in one of the PATH directories.

In the System Environment Variables, Path includes C:\Program Files\nodejs and C:\Users\me\AppData\Roaming\npm amongst others.

Entering 'npm' in the VS 2019 Package Manager Console produces no errors and finishes with [email protected] C:\Program Files\nodejs\node_modules\npm. So that appears OK.

The InnerException on the page includes:

System.ComponentModel.Win32Exception (267): The directory name is invalid.

This error has been documented and marked as resolved at:

https://github.com/aspnet/AspNetCore/issues/6342

"but the real rub is hidden in the InnerException:

System.ComponentModel.Win32Exception: The directory name is invalid.
"

But I'm still having the problem with VS 2019...

Any ideas how to resolve this?

System.AggregateException: One or more errors occurred. (One or more errors occurred. (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:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\PuTTY\;C:\Program Files (x86)\Bitvise SSH Client;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\nodejs\;C:\Users\00082563\AppData\Local\Microsoft\WindowsApps;C:\Users\00082563\.dotnet\tools;C:\Users\00082563\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\00082563\AppData\Roaming\npm;C:\Users\00082563\.nuget\packages\node.js\5.3.0\tools
    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.AggregateException: One or more errors occurred. (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:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\PuTTY\;C:\Program Files (x86)\Bitvise SSH Client;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\nodejs\;C:\Users\00082563\AppData\Local\Microsoft\WindowsApps;C:\Users\00082563\.dotnet\tools;C:\Users\00082563\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\00082563\AppData\Roaming\npm;C:\Users\00082563\.nuget\packages\node.js\5.3.0\tools
    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.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:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\PuTTY\;C:\Program Files (x86)\Bitvise SSH Client;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\nodejs\;C:\Users\00082563\AppData\Local\Microsoft\WindowsApps;C:\Users\00082563\.dotnet\tools;C:\Users\00082563\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\00082563\AppData\Roaming\npm;C:\Users\00082563\.nuget\packages\node.js\5.3.0\tools
    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 (267): The directory name is invalid.

   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)

   at System.Diagnostics.Process.Start()

   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)

   at Microsoft.AspNetCore.NodeServices.Npm.NpmScriptRunner.LaunchNodeProcess(ProcessStartInfo startInfo)

   --- End of inner exception stack trace ---

   at Microsoft.AspNetCore.NodeServices.Npm.NpmScriptRunner.LaunchNodeProcess(ProcessStartInfo startInfo)

   at Microsoft.AspNetCore.NodeServices.Npm.NpmScriptRunner..ctor(String workingDirectory, String scriptName, String arguments, IDictionary`2 envVars)

   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.Builder.RouterMiddleware.Invoke(HttpContext httpContext)

   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

I have submitted the problem at:

https://developercommunity.visualstudio.com/content/problem/858687/failed-to-start-npm-ensure-that-npm-is-installed-a.html

like image 826
IlludiumPu36 Avatar asked Dec 17 '19 03:12

IlludiumPu36


2 Answers

This issue is discussed and resolved here:

https://github.com/dotnet/aspnetcore/issues/6342#issue-395713046

The error message is a red herring. The real problem is that the path to your Client App is wrong. The Visual Studio template puts it in the wrong place.

Open startup.cs, look for Configuration.RootPath, and spa.Options.SourcePath, and make sure they are set to real paths. If not, fix them.

like image 105
FunkMonkey33 Avatar answered Oct 21 '22 08:10

FunkMonkey33


I was getting the same error. I opened cmd as an administrator and ran command npm install -g npm as user12076510 said and restarted the system--error gone away

like image 37
Intesar Alam Avatar answered Oct 21 '22 08:10

Intesar Alam