Javascriptservices: "Failed to start Node process" error with node in environment PATH

Created on 23 Feb 2017  ·  18Comments  ·  Source: aspnet/JavaScriptServices

I am receiving the following error when I host my asp.net core on IIS:

System.InvalidOperationException: Failed to start Node process. To resolve this:.

[1] Ensure that Node.js is installed and can be found in one of the PATH directories.
    Current PATH enviroment variable is: C:\Program Files\PHP\v7.1;C:\Program Files\Microsoft MPI\Bin\;C:\tools\ruby193\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\nodejs\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files\Git\cmd;C:\Program Files\SlikSvn\bin;C:\Program Files\TortoiseSVN\bin;C:\Users\mark\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program File;C:\Program Files (x86)\Yarn\bin;C:\Users\mark\AppData\Roaming\nvm;C:\Program Files\dotnet\;C:\DevDrive;C:\WINDOWS\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;C:\Program Files\dotnet\shared\Microsoft.NETCore.App\1.1.0
    Make sure the Node executable is in one of those directories, or update your PATH.

[2] See the InnerException for further details of the cause. ---> System.ComponentModel.Win32Exception: The system cannot find the file specified
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance.LaunchNodeProcess(ProcessStartInfo startInfo)
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance.LaunchNodeProcess(ProcessStartInfo startInfo)
   at Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance..ctor(String entryPointScript, String projectPath, String[] watchFileExtensions, String commandLineArguments, ILogger nodeOutputLogger, IDictionary`2 environmentVars, Int32 invocationTimeoutMilliseconds, Boolean launchWithDebugging, Int32 debuggingPort)
   at Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance..ctor(NodeServicesOptions options, Int32 port)
   at Microsoft.AspNetCore.NodeServices.HostingModels.NodeServicesOptionsExtensions.<>c__DisplayClass0_0.<UseHttpHosting>b__0()
   at Microsoft.AspNetCore.NodeServices.NodeServicesImpl.GetOrCreateCurrentNodeInstance()
   at Microsoft.AspNetCore.NodeServices.NodeServicesImpl.<InvokeExportWithPossibleRetryAsync>d__10`1.MoveNext()

As you can see nodejs is present in the PATH as C:\Program Files\nodejs\
I can use node from the command line perfectly.

I think that this problem may be related to the fact that the C:\Program Files\nodejs path is in fact a symbolic link to C:\Users\mark\AppData\Roaming\nvm\v7.5.0 because I use nvm-windows to manage multiple versions of node on my dev machine.

Most helpful comment

FOR VS MAC

Right Click Project, click "Options" Go to Run-> Configuration -> Default on the left pane.
I added a PATH variable and the value is (w/o quote):

"/Library/Frameworks/Mono.framework/Commands:/Applications/Visual Studio.app/Contents/Resources:/Applications/Visual Studio.app/Contents/MacOS:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:/usr/local/bin/"

I appended ":/usr/local/bin/" where node js resides..

I got the values other than ":/usr/local/bin/" from the error thrown...

Hope this helps.. mga bes 👍

All 18 comments

i have the same error. I'm using Node Version Manager (nvm) for Windows. https://github.com/coreybutler/nvm-windows.

As a current workaround i set the path variable via Environment.SetEnvironmentVariable...

Can you elaborate on how you set the environment variable on the build file? I am having this same issue with visual studio mac, it won't recognize any of my Paths, and i don't have access to change the Path through external tools. (Which sucks btw)

I tried referencing the direct path in the exec command but it still tries to load node via some fault $PATH it has set itself.

<Exec Command="/usr/local/bin/npm install" />
<Exec Command="/usr/local/bin/node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
<Exec Command="/usr/local/bin/node node_modules/webpack/bin/webpack.js --env.prod" />

In .net there is a static classs called Enviroment. I get the current path with Enviroment.GetEnviromentVariable("%path%") and prepend the known path of node on my system to the path variable and set it with Environment.SetEnvironmentVariable

before the exception triggers, like before node is called, i do this. and ofc it will only work on my system.
I don't know if it works on linux. But i cant imagine that you cant use it there...

Okay, that makes sense. I'll play around with it. I had tried changing Environment Variables At Build but it didn't work, unfortunately.

VS for mac is a preview so i hope they straighten this issue out before launching.

FOR VS MAC

Right Click Project, click "Options" Go to Run-> Configuration -> Default on the left pane.
I added a PATH variable and the value is (w/o quote):

"/Library/Frameworks/Mono.framework/Commands:/Applications/Visual Studio.app/Contents/Resources:/Applications/Visual Studio.app/Contents/MacOS:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:/usr/local/bin/"

I appended ":/usr/local/bin/" where node js resides..

I got the values other than ":/usr/local/bin/" from the error thrown...

Hope this helps.. mga bes 👍

@jvaleroso That worked beautifully!!! Thank you for that!

@dashcraft Hope they fix all the issues in VS Mac because there's a lot.. I switched to Windows because of frustration..

@jvaleroso Thank you! your suggestion worked for me too.

@jvaleroso you pointed us to right direction, but setting the value to just node path which in my case /Users/emish/.nvm/versions/node/v7.9.0/bin/ worked with me there was no need to append all what you mentioned.

Thank you

This is happening for me as well on a Windows box

I've just verified that the latest versions of nvm-windows and the NodeServices package work together correctly (i.e., when the nodejs dir in Program Files is a symlink). The original issue reported here is now resolved so I'll close this.

I appreciate that there will be other situations where .NET code is unable to locate the Node executable (e.g., with VS for Mac, in situations where the IDE process doesn't have the same path env dir as your terminal processes, which is outside our control). For us to make any progress with understanding and resolving such other issues, it's important that they are filed as separate issues with their own separate repro steps rather than just being hinted at in comments here where we don't know if it's the same issue or not. So, if you are still having trouble, please file a new issue with clear repro steps. Thanks!

Nodejs version problem? 6.3.1.0 worked for me but not 6.11

@SteveSandersonMS - which version of NodeServices was this fixed in?

It was never explicitly fixed, but rather when I checked if it was working with the latest version as of my post on 3 July, it was working then. So I don't know if it really was broken with some earlier version, only that it wasn't broken on 3 July.

The current version is 2.0 so please make sure you're using that. If you find some way to repro this issue with 2.0 and can give repro steps, please let us know!

I have a simple repro using 2.0. I have no node.exe in the path except for the one specified by "nvm use" (c:Program filesnodejs symbolic link). Create a .NET Core Angular 2 app, on the .NET Framework (not on .NET Core). Build and run dotnet publish -o ..Publish. Create an IIS website pointing to that location, and it fails with the error above. I have tried a host of node versions (6.10.x, 6.11.x, 8.2.x, 8.4.x, 7.5.0), but all fail. I even tried copying node.exe to windowssystem32, and it still fails. The only difference I see from a "normal" app is .NET Core on .NET Framework instead of .NET Core.

If you're deploying to IIS, there's a very good chance this is a permissions issue. To quickly check this, you might want to change your app pool to run as Local System or similar and see if that fixes it. But then you should change back to App Pool Identity any add whatever file access permissions are needed (e.g., you might need to grant read permission on the c:Program filesnodejs symlink plus whatever directory contains the Node app files it links to).

I got this error after adding Docker support to my project and tried running the project through docker. I wasn't suprised to get this in debug mode but didn't expect to get it in release mode so I may not fully understand how JS Services works.

I got the error fixed by first getting my Node path
❯ which node /Users/eddyekofo/.nvm/versions/node/v10.11.0/bin/node
Then Added the path to "Options" Go to Run-> Configuration -> Default on the left pane.
I added a PATH variable:
/Users/eddyekofo/.nvm/versions/node/v10.11.0/bin

Worked on MacOS Mojave

Was this page helpful?
0 / 5 - 0 ratings

Related issues

harsimranb picture harsimranb  ·  3Comments

dantheman999301 picture dantheman999301  ·  4Comments

justinyoo picture justinyoo  ·  3Comments

natemcmaster picture natemcmaster  ·  4Comments

mounthorse-slns picture mounthorse-slns  ·  3Comments