Visual Studio Docker在node.js不在路径上时失败 [英] Visual Studio Docker failing on node.js not being in path when it is

查看:134
本文介绍了Visual Studio Docker在node.js不在路径上时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的PC(Docker桌面)上安装了Docker,并在Azure Devops中为我的SPA(Aurelia)创建了一个git存储库。我发现我拥有 Docker,而不是用于运行项目的IISExpress。我单击泊坞窗运行它,一直进行到整个过程,然后出现以下异常。似乎很简单,我的路径上没有node.js,除了它是..我已经用谷歌搜索过,并且在添加Node时有几个问题。所以我将其添加到用户变量中。系统变量。然后删除所有条目并重新安装Node ..,然后将node添加到路径本身。然后我重新启动并再次重新运行该项目-首先在IISExpress中-成功-然后在Docker中,您可以再次看到该异常。.我不知道为什么当Node在机器上,在路径中并且仍然抛出时

I have installed Docker on my PC - Docker Desktop - and have created a git repository in Azure Devops for my SPA (Aurelia). I find I have, instead of IISExpress for running the project, I have "Docker". I click on "Docker" to run it and it goes all the way through and then I get the following exception. Seems simple enough that I dont have node.js in my path except that it is.. I have googled this and there are a couple of questions on adding Node.. So I added it to the user variables.. I have added it to the System variables. I then deleted all entries and re-installed Node.. which then added node to the path itself. I then re-started and again re-ran the project - first in IISExpress - success - then in Docker and you can see the exception again.. I have no idea why when Node is on the machine and in the path and its still throwing an exception??

    System.AggregateException
  HResult=0x80131500
  Message=One or more errors occurred. (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:\Windows\system32;C:\Windows;C:\Users\ContainerAdministrator\AppData\Local\Microsoft\WindowsApps;C:\Program Files\dotnet;C:\Users\ContainerUser\AppData\Local\Microsoft\WindowsApps
    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.)
  Source=System.Private.CoreLib
  StackTrace:
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at Microsoft.AspNetCore.Builder.WebpackDevMiddleware.UseWebpackDevMiddleware(IApplicationBuilder appBuilder, WebpackDevMiddlewareOptions options)
   at JobsLedgerAPI.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in C:\AURELIA\1. - JOBSLEDGER SPA\JobsLedgerSPA\JobsLedgerAPI\Startup.cs:line 44

Inner Exception 1:
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:\Windows\system32;C:\Windows;C:\Users\ContainerAdministrator\AppData\Local\Microsoft\WindowsApps;C:\Program Files\dotnet;C:\Users\ContainerUser\AppData\Local\Microsoft\WindowsApps
    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.

Inner Exception 2:
Win32Exception: The system cannot find the file specified


推荐答案

由于您已经在PC上提到 ,因此我认为在PC上运行Node.js应用需要 iisnode模块。在您的 web中进行配置。 config 负责运行Node.js进程,并执行主文件 Node.exe (例如 server.js / main.js / app.js )和整个应用程序生命周期。

Since you have mentioned on my PC, I believe that running Node.js app on your PC needs iisnode module. Its configuration in your web.config takes care of running the Node.js process and the main file Node.exe executes (e.g. server.js/main.js/app.js) and the whole app lifecycle.

示例如下:

    <handlers>
          <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
        </handlers>
<!--...-->

    <iisnode
          nodeProcessCommandLine="&quot;%programfiles%\nodejs\node.exe&quot;" 
          interceptor="&quot;%programfiles%\iisnode\interceptor.js&quot;" />

希望它会有所帮助。相同的模块还有助于在Azure上运行Node.js应用程序(docker基础结构也可能使用相同的模块)。

Hope it helps. Same module also helps running the Node.js app on Azure (docker infrastructure might be using same module as well).

其他参考:在Windows上安装iisnode

PS:
您可能必须根据IIS版本(Express / regular等)安装适当的iisnode模块版本。

PS: You may have to install appropriate iisnode module version as per your IIS version (Express/regular etc.).

我有带IIS 7.5的Windows 7 64位操作系统。我安装了 iisnode 。之后,我按照此页面上列出的说明进行操作。然后它将我的Node.js应用程序加载到 http:// localhost:82 / 上。您可能还必须授予用户 IIS_IUSRS 适当的权限( READ )对您托管节点的文件夹的权限。 js网络应用及其父文件夹(欢迎使用新技巧!)。

I have Windows 7 64-bit OS w/ IIS 7.5. I installed iisnode. After that, I followed the instructions as listed on this page. Then it loaded my Node.js app on http://localhost:82/. You also might have to give the user IIS_IUSRS proper permissions (READ) to the folder where you are hosting your Node.js web app and its parent folder as well (welcome new tricks!).

我从本地主机上的节点Web应用程序运行的 web.config 如下:请按照您的计算机进行编辑。

My working web.config from the node web app on localhost:82 follows. Please edit as per your machine.

<configuration>
    <system.webServer>

        <!-- indicates that the server.js file is a node.js application
        to be handled by the iisnode module -->

        <handlers>
            <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
        </handlers>

<globalModules>
    <add name="iisnode" image="C:\Program Files (x86)\iisnode\iisnode.dll" />
</globalModules>
        <rewrite>
            <rules>
                <rule name="sendToNode">
                    <match url="/*" />
                    <action type="Rewrite" url="server.js" />
                </rule>
            </rules>
        </rewrite>

    </system.webServer>
</configuration>

Barebones示例 server.js

Barebones example server.js follows. Please install Express for Node.js unless it is already installed.

var express = require('express');

var app = express();

app.get('/', function (req, res) {
    res.send('Express is working on IISNode!');
});

app.listen(process.env.PORT);

这篇关于Visual Studio Docker在node.js不在路径上时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆