Reputation: 777
I have a Core 2.2 project with Create React App in Visual Studio 2017 and after a 3 month pause on the project I am now returning but I cannot run the application anymore. When running the project I get this error in the browser;
AggregateException: One or more errors occurred. (One or more errors occurred. (Failed to start 'npm'...
It gives me two possibilities to resolve it;
Ensure that 'npm' is installed and can be found in one of the PATH directories...
and
See the InnerException for further details of the cause. ---> System.ComponentModel.Win32Exception: 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)
Npm is installed and is located in one of the suggested directories so that shouldnt be the issue. The files havent changed so cannot se why a directory name should be invalid - the only change since last is a Visual Studio versioning upgrade. I have installed VS2019 but it gives me same error. Debugging in VS doesnt break, the error only shows in the browser.
What to do?
Upvotes: 4
Views: 11068
Reputation: 1
Setting source path as follows worked for me;
app.UseSpa(spa =>
{
spa.Options.SourcePath = env.ContentRootPath+ "\\..\\" + "ShifuCodeClient";
if (env.IsDevelopment())
{
spa.UseAngularCliServer(npmScript: "start");
}
});
Upvotes: 0
Reputation: 7407
From the following issue on GitHub: https://github.com/aspnet/AspNetCore/issues/6342#issue-395713046
- JavaScriptServices reports any failure in the call to npm as a PATH problem for NPM, when it's reasonably probable (if not more likely) that the real problem is the SourcePath was set to a directory that doesn't exist.
- Our Templates SourcePath of "ClientApp" does not work in all circumstances
Upvotes: 3