我在ASP.Net Core应用程序中使用Microsoft.AspNetCore.NodeServices 1.1.1
。一切都运行良好,但现在我在一台新电脑上,我收到以下错误:
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: ....
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.
我已从此问题中删除了路径变量,但其中列出了安装Node的目录。
终端中的 node -v
会向我v6.11.0
,因此会将其添加到路径中。
自上次工作以来,代码中没有任何内容发生变化,只有我的电脑。有谁知道什么可能是错的?
答案 0 :(得分:5)
调试后我发现它是由于文件夹丢失造成的。
这是NodeServices
中Startup.cs
的配置方式:
services.AddNodeServices(options =>
{
options.ProjectPath = "Path\That\Doesnt\Exist";
});
一旦我添加了这条路径,一切都运行正常。
答案 1 :(得分:1)
您可以使用此代码段获取客户端项目
services.AddNodeServices(options =>{
options.ProjectPath = Path.Combine(Directory.GetCurrentDirectory(), "ClientApp"); });
答案 2 :(得分:0)
对我来说,该错误是将我的网站从Net Core 2.2升级到3.0后引起的。
升级更改了我的web.config
文件,尤其是这一部分:
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\MyWebsite.exe" arguments="" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
成为这个:
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" hostingModel="inprocess">
<environmentVariables>
<environmentVariable name="COMPLUS_ForceENC" value="1" />
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
我通过将processPath
和arguments
设置回原来的值来解决此问题,并完全删除了<environmentVariables>
部分。