error MSB3073: The command "npm install" exited with code 1
Asked Answered
S

5

9

i was containerizing my .Net + React.js application but during the process I have encountered an unexpected error. I got myself acquainted with similar posts but none of the solutions solved my problem. Since the build log is quite long I have placed in pastebin:

https://pastebin.com/PhfYW3zm

The dockerfile which I am using comes from the official documentation, and that's why it comes to me as a surpise that it does not work:

https://learn.microsoft.com/en-us/visualstudio/containers/container-tools-react?view=vs-2022

The Dockerfile itself:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y libpng-dev libjpeg-dev curl libxi6 build-essential libgl1-mesa-glx
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get install -y nodejs

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y libpng-dev libjpeg-dev curl libxi6 build-essential libgl1-mesa-glx
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get install -y nodejs
WORKDIR /src
COPY ["WebApp/WebApp.csproj", "WebApp/"]
RUN dotnet restore "WebApp/WebApp.csproj"
COPY . .
WORKDIR "/src/WebApp"
RUN dotnet build "WebApp.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "WebApp.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApp.dll"]
Squamous answered 14/12, 2021 at 21:58 Comment(0)
S
8

Deleting the npm install tags from .csproj as suggested in this thread https://github.com/dotnet/sdk/issues/9593 by user PKLeso resolved the problem.

<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" /> 

This will delete frontend from your container completely if I remember correctly. However if you want to remain it within container just make sure that npm install on your frontend leaves no errors. Beacuse otherwise MSB3073 error occurs.

Squamous answered 24/12, 2021 at 1:4 Comment(0)
Z
1

If there are dependency conflicts in the react app, for example after an upgrade of react to to the latest version, and because of that npm install invoked on the ClientApp does not run but npm install --force does run then in the .csproj add --force to the

<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />

line, so it becomes

<Exec WorkingDirectory="$(SpaRoot)" Command="npm install --force" />
Zone answered 12/3, 2023 at 13:44 Comment(0)
C
0

Don't know if it could still be of interest, but actually I found it useful to use the ContinueOnError="true" xml attribute.

<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" ContinueOnError="true"/>
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --configuration production" ContinueOnError="true" />

This way every exception that npm will thrown (like the vulnerability messages) will be ignored and the build will continue, installing npm packages and building frontend node assets.

Cratch answered 2/6, 2023 at 20:56 Comment(0)
L
0

For me, the issue was I was using old version of node, by running the command npm install on the client directory you get to see the exact error message.

So using to a compatible npm version using nvm solved the problem.

Leiva answered 1/6 at 11:35 Comment(0)
M
0

Changing the Node version solved the issue for me. I was initially using version 20.17.0, the latest LTS version as of September 2024, but switching to either version 20.14.0 or 20.11.0 resolved the issue.

Mccowan answered 17/9 at 20:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.