Как добавить package.json в скомпилированное приложение? ASP.Net Core 5, React.js

При деплое приложения в папку, кестрел сервер исправно его запускает. Но мне необходимо запустить его в Docker контейнере, но я получаю ошибку :


npm ERR! syscall open

npm ERR! path /app/ClientApp/App/package.json

npm ERR! errno -2

npm ERR! enoent ENOENT: no such file or directory, open '/app/ClientApp/App/package.json'

npm ERR! enoent This is related to npm not being able to find a file.

npm ERR! enoent 

После компиляции в папке с клиентским приложением, файл package.json отсутствует. Подскажите пожалуйста, каким образом я могу добавить нужные файлы при компиляции? И почему в контейнере он просит package.json если при запуске через IIs и Kestrel все происходит успешно?

В самом контейнере декер стоит следующий npm, node.js

# npm -v
8.1.0
# node -v
v16.13.0
#

Файл package.json;

{
  "name": "app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^11.2.7",
    "@testing-library/user-event": "^12.8.3",
    "anime": "^0.1.2",
    "animejs": "^3.2.1",
    "Base64": "^1.1.0",
    "connected-react-router": "^6.9.1",
    "crypto-js": "^4.1.1",
    "history": "^4.10.1",
    "js-cookie": "^3.0.1",
    "latest-version": "^6.0.0",
    "react": "^17.0.2",
    "react-anime": "^4.1.1",
    "react-dom": "^17.0.2",
    "react-redux": "^7.2.5",
    "react-router": "^5.0.0",
    "react-router-dom": "^5.0.0",
    "react-router-redux": "4.0.8",
    "react-scripts": "4.0.3",
    "redux": "^4.1.1",
    "web-vitals": "^1.1.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Файл csproj:

<Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup>
        <TargetFramework>net5.0</TargetFramework>
        <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
        <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
        <IsPackable>false</IsPackable>
        <SpaRoot>ClientApp\App\</SpaRoot>
        <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
        <RootNamespace>Proj</RootNamespace>
        <UserSecretsId>553ad427-16bf-4ffb-9c68-cdc1c61d6aee</UserSecretsId>
        <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
        <DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="5.0.8" />
        <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.8" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.8" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.8">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.14" />
        <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
        <PackageReference Include="RestSharp" Version="106.12.0" />
    </ItemGroup>

    <ItemGroup>
        <!-- Don't publish the SPA source files, but do show them in the project files list -->
        <Content Remove="$(SpaRoot)**" />
        <None Remove="$(SpaRoot)**" />
        <None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
    </ItemGroup>

    <ItemGroup>
      <None Remove="ClientApp\App%2a%2a" />
    </ItemGroup>

    <Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
        <!-- Ensure Node.js is installed -->
        <Exec Command="node --version" ContinueOnError="true">
            <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
        </Exec>
        <Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
        <Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
        <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
    </Target>

    <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
        <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
        <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
        <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" />


        <!-- Include the newly-built files in the publish output -->
        <ItemGroup>
            <DistFiles Include="$(SpaRoot)build\**" />
            <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
                <RelativePath>%(DistFiles.Identity)</RelativePath>
                <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
                <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
            </ResolvedFileToPublish>
        </ItemGroup>
    </Target>

</Project>

Файл Dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
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_16.x | bash -
RUN apt-get install -y nodejs
WORKDIR /app

EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:5.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_16.x | bash -
RUN apt-get install -y nodejs
WORKDIR /src
COPY ["Proj/Proj.csproj", "Proj/"]
RUN dotnet restore "Proj/Proj.csproj"
COPY . .
WORKDIR "/src/Proj"
RUN dotnet build "Proj.csproj" -c Release -o /app/build

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

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

Ответы (0 шт):