【问题标题】:Visual Studio Docker failing on node.js not being in path when it is当 node.js 不在路径中时,Visual Studio Docker 失败
【发布时间】:2019-04-26 20:36:03
【问题描述】:

我已经在我的 PC 上安装了 Docker - Docker Desktop - 并在 Azure Devops 中为我的 SPA (Aurelia) 创建了一个 git 存储库。我发现我有,而不是 IISExpress 来运行项目,我有“Docker”。我单击“Docker”运行它,它一直运行,然后我得到以下异常。似乎很简单,我的路径中没有node.js,除了它是......系统变量。然后我删除了所有条目并重新安装了 Node.. 然后将节点添加到路径本身。然后我重新启动并再次重新运行项目 - 首先在 IISExpress 中 - 成功 - 然后在 Docker 中,你可以再次看到异常。我不知道为什么当 Node 在机器上和路径中并且它仍然抛出例外??

    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

【问题讨论】:

    标签: node.js docker


    【解决方案1】:

    既然您提到了on my PC,我相信在您的PC 上运行Node.js 应用程序需要iisnode module。它在 web.config 中的配置负责运行 Node.js 进程和主文件 Node.exe 执行(例如 server.js/main.js/app.js)和整个应用程序生命周期。

    示例如下:

        <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 基础设施也可能使用相同的模块)。

    其他参考:Installing iisnode On Windows

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

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

    我的工作 web.config 来自 localhost:82 上的节点 Web 应用程序。请根据您的机器进行编辑。

    <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>
    

    下面是准系统示例server.js。请安装 Express for Node.js,除非它已经安装。

    var express = require('express');
    
    var app = express();
    
    app.get('/', function (req, res) {
        res.send('Express is working on IISNode!');
    });
    
    app.listen(process.env.PORT);
    

    【讨论】:

    • 是的,我被诅咒了.. IISnode 不会安装。它说“这个 Windows 安装程序包有问题。无法运行完成安装所需的脚本......当然这应该只是安装......??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-25
    • 1970-01-01
    • 1970-01-01
    • 2011-08-19
    • 2023-03-09
    • 1970-01-01
    • 2019-05-27
    相关资源
    最近更新 更多