I\'m developing an Asp.Net Core 2 and Angular 5 project in visual studio 2017.
When I\'m going to publish my project then the error \'The command \"npm run
From the error in your output window, it seems that the npm build command is targeting the wrong directory and cannot find the package.json file to perform its build:
11 error code ENOENT
12 error errno -4058
13 error syscall open
14 error enoent ENOENT: **no such file or directory, open** 'C:\Project\JWS\JWSApplication\package.json'
15 error enoent ENOENT: no such file or directory, open
'C:\Project\JWS\JWSApplication\package.json'
15 error enoent This is most likely not a problem with npm itself
15 error enoent and is related to npm not being able to find a file.
16 verbose exit [ -4058, true ]
I suspect your msbuild is targeting your root project folder instead of your ClientApp/SpaRoot folder where your package.json file will be located.(Guess based on similar experience since I do not have access to your .csproj to inspect your msbuild configurations).
If you open your .csproj file, you should see where the ClientApp/SpaRoot file is located. Ideally, it will be something like below:
<PropertyGroup>
<SpaRoot>ClientApp\</SpaRoot>
<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
</PropertyGroup>
Based on the above, the directory path to your ClientApp/SpaRoot folder will be configured which contains the package.json file and will be used when calling npm build
during deployment:
<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 --prod" />
<Exec **WorkingDirectory="$(SpaRoot)"** Command="npm run build:ssr --prod" Condition=" '$(BuildServerSideRenderer)' == 'true' " />
<!-- Include the newly-built files in the publish output -->
<ItemGroup>
<DistFiles Include="$(SpaRoot)dist\**; $(SpaRoot)dist-server\**" />
<DistFiles Include="$(SpaRoot)node_modules\**" Condition="'$(BuildServerSideRenderer)' == 'true'" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>%(DistFiles.Identity)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</ResolvedFileToPublish>
</ItemGroup>
</Target>
Got same error, my environment:
.NET Core 2.1 RC-1
Angular v5.2.4
NPM v5.7.1
Node v8.11.2
And nothing mentioned above did not helped. Simple go to ".\ClientApp" //Angula-CLI project and run
npm run build
then you will see real errors - so that means simple you have some errors in code, so fix angular UI code and it will build fine :).