When setting the environment to development, I get an error regarding NPM

Viewed 95

I'm trying to containerize an app with ASP.Net core & Angular.

It works perfectly - except for one thing. If I edit the Angular code, the pages do not update. After some research, I found out that I need to set the environment to development for my pages to get updated.

No problem - I can do that. I set it and then I get

asp.net | fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
asp.net |       An unhandled exception has occurred while executing the request.
asp.net |       System.AggregateException: One or more errors occurred. (One or more errors occurred. (Failed to start 'npm'. To resolve this:.
asp.net |
asp.net |       [1] Ensure that 'npm' is installed and can be found in one of the PATH directories.
asp.net |           Current PATH enviroment variable is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
asp.net |           Make sure the executable is in one of those directories, or update your PATH.
asp.net |
asp.net |       [2] See the InnerException for further details of the cause.))
asp.net |        ---> System.AggregateException: One or more errors occurred. (Failed to start 'npm'. To resolve this:.
asp.net |
asp.net |       [1] Ensure that 'npm' is installed and can be found in one of the PATH directories.
asp.net |           Current PATH enviroment variable is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
asp.net |           Make sure the executable is in one of those directories, or update your PATH.
asp.net |
asp.net |       [2] See the InnerException for further details of the cause.)
asp.net |        ---> System.InvalidOperationException: Failed to start 'npm'. To resolve this:.
asp.net |
asp.net |       [1] Ensure that 'npm' is installed and can be found in one of the PATH directories.
asp.net |           Current PATH enviroment variable is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
asp.net |           Make sure the executable is in one of those directories, or update your PATH.
asp.net |
asp.net |       [2] See the InnerException for further details of the cause.
asp.net |        ---> System.ComponentModel.Win32Exception (2): No such file or directory
asp.net |          at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
asp.net |          at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
asp.net |          at System.Diagnostics.Process.Start()
asp.net |          at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
asp.net |          at Microsoft.AspNetCore.NodeServices.Npm.NodeScriptRunner.LaunchNodeProcess(ProcessStartInfo startInfo, String commandName)
asp.net |          --- End of inner exception stack trace ---
asp.net |          at Microsoft.AspNetCore.NodeServices.Npm.NodeScriptRunner.LaunchNodeProcess(ProcessStartInfo startInfo, String commandName)
asp.net |          at Microsoft.AspNetCore.NodeServices.Npm.NodeScriptRunner..ctor(String workingDirectory, String scriptName, String arguments, IDictionary`2 envVars, String pkgManagerCommand, DiagnosticSource diagnosticSource, CancellationToken applicationStoppingToken)
asp.net |          at Microsoft.AspNetCore.SpaServices.AngularCli.AngularCliMiddleware.StartAngularCliServerAsync(String sourcePath, String scriptName, String pkgManagerCommand, Int32 portNumber, ILogger logger, DiagnosticSource diagnosticSource, CancellationToken applicationStoppingToken)
asp.net |          --- End of inner exception stack trace ---
asp.net |          at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
asp.net |          at System.Threading.Tasks.Task`1.get_Result()
asp.net |          at Microsoft.AspNetCore.SpaServices.AngularCli.AngularCliMiddleware.<>c.<Attach>b__2_0(Task`1 task)
asp.net |          at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
asp.net |          at System.Threading.Tasks.Task.<>c.<.cctor>b__277_0(Object obj)
asp.net |          at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
asp.net |       --- End of stack trace from previous location ---
asp.net |          at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
asp.net |          at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
asp.net |          --- End of inner exception stack trace ---
asp.net |          at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
asp.net |          at System.Threading.Tasks.Task`1.get_Result()
asp.net |          at Microsoft.AspNetCore.SpaServices.Extensions.Util.TaskTimeoutExtensions.WithTimeout[T](Task`1 task, TimeSpan timeoutDelay, String message)
asp.net |          at Microsoft.AspNetCore.SpaServices.Extensions.Proxy.SpaProxy.PerformProxyRequest(HttpContext context, HttpClient httpClient, Task`1 baseUriTask, CancellationToken applicationStoppingToken, Boolean proxy404s)
asp.net |          at Microsoft.AspNetCore.Builder.SpaProxyingExtensions.<>c__DisplayClass2_0.<<UseProxyToSpaDevelopmentServer>b__0>d.MoveNext()
asp.net |       --- End of stack trace from previous location ---
asp.net |          at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

for some reason. I don't know how to fix it.

My dockerfile:

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 5000
RUN curl -sL https://deb.nodesource.com/setup_10.x |  bash -
RUN apt-get update
RUN apt-get install -y nodejs
#EXPOSE 5001

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["mediere.csproj", "."]
RUN dotnet restore "./mediere.csproj"
COPY . .
WORKDIR "/src/."
RUN curl -sL https://deb.nodesource.com/setup_10.x |  bash -
RUN apt-get install -y nodejs
RUN dotnet build "mediere.csproj" -c Release -o /app/build

FROM build AS publish
RUN curl -sL https://deb.nodesource.com/setup_10.x |  bash -
RUN apt-get install -y nodejs
RUN npm install zone.js@0.11.3 --save
RUN dotnet publish "mediere.csproj" -c Release -o /app/publish

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

my docker-compose.yml

version: "3.9"
services:
    web:
        container_name: asp.net
        build: 
           context: .
           dockerfile: Dockerfile            
        ports:
            - "5000:5000"
        environment:
             ASPNETCORE_URLS: "http://+:5000"
        depends_on:
            - db
    db:
        container_name: postgres
        image: postgres:latest
        ports: 
            - "5432"
        restart: always
        volumes:
            - db_volume:/var/lib/postgresql/data
        environment:
            POSTGRES_USER: ""
            POSTGRES_PASSWORD: ""
            POSTGRES_DB: ""
            
volumes:
   db_volume:

as I said - as long as I don't set the environemnt to Development, everything works just fine. (but the pages do not update on editing the files)

So... how can I fix this error?

Thanks.

0 Answers
Related