Skip to main content

Solving MSB6003 Error for ASP.NET Core Docker Image Build

Trying to build a Linux Docker image for ASP.NET Core project with Typescript support leads to a build error "MSB6003: The specified task executable "node" could not be run". The reason is Linux.

On Windows, Microsoft.TypeScript.MSBuild includes tsc.exe. On non-Windows platforms, such as in a Docker container, Microsoft.TypeScript.MSBuild does not include ts.exe and instead shells out to a Node for the TypeScript compiler. The official dotnet/sdk Docker images I think included Node at one point in the past, but they no longer include Node. You will either need to make or find a Docker image with both the dotnet-sdk and Node, or configure some multi-stage build involving the official Node image [1].

Ok, if I know the reason then I will solve it in a minute. I thought. It turned out to be a quest to install the actual version of Node. Official Microsoft's image for dotnet is based on Debian (12 at the moment for .NET 8.0). So, the straight forward way would be using apt-get. Unfortunately, the version there is outdated. I also tried nodesource.com and nvm with no luck.

So I ended up with the following command installing LTS version:

apt-get update && apt-get install -y \
    software-properties-common npm && \
    curl https://www.npmjs.com/install.sh | sh && \
    npm install n -g && \
    n lts

To incorporate it in the Dockerfile, add the following lines in the build section (right under "FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build"):
USER root
# NodeJS is required for building Typescript on non-Windows platforms
RUN apt-get update && apt-get install -y \
    software-properties-common npm && \
    curl https://www.npmjs.com/install.sh | sh && \
    npm install n -g && \
    n lts

Please pay attention to USER command. It's not needed for .NET 7 and earlier since dotnet images are created under root user. Starting since .NET 8.0 images are rootless. This may lead to one more issue unrelated to the original one. Image build may fail on project restore, build, and publish because of insufficient permissions accessing some folder, "obj" for instance. So, it needs to be built under root and then chmod the publish folder after publish completion.
RUN chmod -R 777 /app/publish
USER app

Comments