Robert Vandenberg
Robert Vandenberg

Reputation: 305

Nuget package Microsoft.TypeScript.MSBuild fails in Dockerfile

I have an ASP.NET Core project that includes several TypeScript files. The project has Microsoft.TypeScript.MSBuild reference to automatically compile these TS files to JavaScript files.

  <ItemGroup>
    <PackageReference Include="Microsoft.TypeScript.MSBuild" Version="3.2.3" />
  </ItemGroup>

The setting worked until I tried to dockerize my project. When I follow the example here, the error occurs:

/root/.nuget/packages/microsoft.typescript.msbuild/3.2.3/tools/Microsoft.TypeScript.targets(305,5): error MSB6003: The specified task executable "node" could not be run. No such file or directory [/app/MyProject.csproj] The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1

How to resolve the issue?

Upvotes: 16

Views: 3732

Answers (3)

xRavisher
xRavisher

Reputation: 867

Thanks for the question! Saved me from asking it myself.

For me the fix was as simple as running sudo apt-get install nodejs (Using Ubuntu 18.04)

Upvotes: 2

Ivan Valadares
Ivan Valadares

Reputation: 949

In linux containers You have to install node first. Add the following lines to your dockerfile. Add it before "RUN dotnet build"

RUN apt-get update -yq && apt-get upgrade -yq && apt-get install -yq curl git nano
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && apt-get install -yq nodejs build-essential
RUN npm install -g npm
RUN npm install

Upvotes: 2

kamcma
kamcma

Reputation: 323

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.

Upvotes: 11

Related Questions