C:\\Program Files\\nodejs\\npm.cmd: The directory name is invalid." Error when integrating a Node.js app into a .NET Aspire applicationfail: Aspire.Hosting.Dcp.dcpctrl.ExecutableReconciler[0]
failed to start a process {
"Executable": {
...
},
...
"error": "fork/exec C:\\Program Files\\nodejs\\npm.cmd: The directory name is invalid."
}
fail: Aspire.Hosting.Dcp.dcpctrl.ExecutableReconciler[0]
failed to start a process {
"Executable": {
...
},
...
"error": "fork/exec C:\\nvm4w\\nodejs\\corepack.cmd: The directory name is invalid."}
I encountered those errors when integrating a Node.js app into a .NET Aspire application because of a stupid mistake: the path I used for the workingDirectory was wrong.
My NodeJS app was three levels of parent directories above my Aspire AppHost project, but I used "../../nodejs-proj-folder" for the workingDirectory parameter of AddNpmApp method.
var nodeJsApp = builder.AddNpmApp("nodeJsApp", "../../nodejs-proj-folder", "start:dev")
...
;
The correct path was supposed to be "../../../nodejs-proj-folder".
I hope this saves someone out there from hours of debugging.
Note: I had nvm installed and was using it to control which version of NodeJS I use in my local machine. I encountered the first error above when using an older version of nvm. The 2nd error I encountered when I updated nvm to the latest version.