首页 文章

AggregateException:发生一个或多个错误 . (发生了一个或多个错误 . (无法启动'npm' . 要解决此问题:

提问于
浏览
2

Mac上的Visual Studio与docker有很多错误让人感到沮丧 . 我,在asp.net core 2.1上有一个项目,在docker镜像上有角度6 . 当项目成功构建但无法在下面运行时,详细信息如下:

An unhandled exception occurred while processing the request. AggregateException: One or more errors occurred. (One or more errors occurred. (Failed to start 'npm'. To resolve this:. 1 Ensure that 'npm' is installed and can be found in one of the PATH directories. Current PATH enviroment variable is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin Make sure the executable is in one of those directories, or update your PATH. 2 See the InnerException for further details of the cause.)) System.Threading.Tasks.Task.GetResultCore(bool waitCompletionNotification) InvalidOperationException: Failed to start 'npm'. To resolve this:. 1 Ensure that 'npm' is installed and can be found in one of the PATH directories. Current PATH enviroment variable is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin Make sure the executable is in one of those directories, or update your PATH. 2 See the InnerException for further details of the cause. Microsoft.AspNetCore.NodeServices.Npm.NpmScriptRunner.LaunchNodeProcess(ProcessStartInfo startInfo)

info for details

added more image

services.AddNodeServices(options =>
            {
                options.ProjectPath = "/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/";
            });

这是docker文件信息

FROM microsoft/dotnet:2.1-sdk AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY MeroRentalDev.sln ./
COPY WebApp/WebApp.csproj WebApp/
RUN dotnet restore -nowarn:msb3202,nu1503
COPY . .
WORKDIR /src/WebApp
RUN dotnet build -c Release -o /app

FROM build AS publish
RUN dotnet publish -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApp.dll"]

尝试了许多链接的解决方案,但无法解决System Aggregation Exception : Failed to start Node Process

Microsoft.AspNetCore.NodeServices: Failed to start node process

https://github.com/aspnet/JavaScriptServices/issues/227

https://github.com/aspnet/JavaScriptServices/issues/707

1 回答

  • 3

    最后解决这个问题 . 这个问题是由于node.js没有安装在asp.net core 2.1 docker镜像上 .

    因此,在docker容器中安装节点js

    # Setup NodeJs
    RUN apt-get update && \
        apt-get install -y wget && \
        apt-get install -y gnupg2 && \
        wget -qO- https://deb.nodesource.com/setup_8.x | bash - && \
        apt-get install -y build-essential nodejs
    # End setup
    

    在修改和更改节点版本值之前,请检查节点的版本 . 在我的情况下,我有8.11.3所以 setup_8.x

    完整的docker文件

    FROM microsoft/dotnet:2.1-sdk AS base
    
        # Setup NodeJs
        RUN apt-get update && \
            apt-get install -y wget && \
            apt-get install -y gnupg2 && \
            wget -qO- https://deb.nodesource.com/setup_8.x | bash - && \
            apt-get install -y build-essential nodejs
        # End setup
        WORKDIR /app
        EXPOSE 80
    
        FROM microsoft/dotnet:2.1-sdk AS build
        WORKDIR /src
        COPY MeroRentalDev.sln ./
        COPY WebApp/WebApp.csproj WebApp/
        RUN dotnet restore -nowarn:msb3202,nu1503
        COPY . .
        WORKDIR /src/WebApp
        RUN dotnet build -c Release -o /app
    
        FROM build AS publish
        RUN dotnet publish -c Release -o /app
    
        FROM base AS final
        WORKDIR /app
        COPY --from=publish /app .
        ENTRYPOINT ["dotnet", "WebApp.dll"]
    

    来源 - https://github.com/aspnet/Announcements/issues/298 Configuring Dockerfile for an ASP.NET Core 2.1 Angular Project

相关问题