Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Release of ASP.NET core App: The command "npm install" exited with code 9009

I have a ASP.NET Core solution with a React frontend. I now have a problem I cannot release the code using the normal release window inside Visual Studio. I publish to a web app inside Azure web apps, and it works perfectly for all my other solutions built the same way.

The code works perfectly locally, and I can run npm install locally without problems.

The error obviously comes from some file not found, when publishing. In my project file I have been debugging and found out this is the challenge:

 <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
    <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
    <Exec Command="npm install" />
    <Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
    <Exec Command="node node_modules/webpack/bin/webpack.js --env.prod" />

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

Error in Visual Studio:

Severity    Code    Description Project File    Line    Suppression State
Error       The command "npm install" exited with code 9009.    Likvido.CreditRisk  C:\Users\MYNAME\Documents\Github\Likvido.CreditRisk\Likvido.CreditRisk\Likvido.CreditRisk\Likvido.CreditRisk.csproj 75  

If I comment out the first three lines (npm install and the two webpacks), I can publish the solution but without working JavaScript obviously.

Any idea how to solve this? And at least, how to debug it better?

Visual error in Visual Studio:

enter image description here

The log file refered in the GUI:

09/04/2018 11.07.03
System.AggregateException: One or more errors occurred. ---> System.Exception: Publish failed due to build errors. Check the error list for more details.
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.Web.Publish.PublishService.VsWebProjectPublish.<>c__DisplayClass40_0.<PublishAsync>b__2()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.ApplicationCapabilities.Publish.ViewModel.ProfileSelectorViewModel.<RunPublishTaskAsync>d__88.MoveNext()
---> (Inner Exception #0) System.Exception: Publish failed due to build errors. Check the error list for more details.<---

===================
like image 753
Lars Holdgaard Avatar asked Apr 09 '18 09:04

Lars Holdgaard


1 Answers

So this was embarrassing but potentially useful for future Googlers.

The underlying problem was quite simple: it was a new computer which did not have Node.js (or NPM) installed. That makes the error message quite useful: node was not found!

The solution is simple: install Node.js, make sure it's in your PATH and restart your computer. Then you will solve this problem.

like image 107
Lars Holdgaard Avatar answered Oct 04 '22 17:10

Lars Holdgaard