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

19,963

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.

Share:
19,963
Lars Holdgaard
Author by

Lars Holdgaard

An entrepreneur since I was 18. Been building a lot of stuff: some successful, some not so successful Currently building the best debt collection company in the world at Likvido. In my free time (when not tinkering with code), I'm very much into crypto, traveling and being digital-nomad when it suits my lifestyle... And I blog at LarsHoldgaard.com!

Updated on June 05, 2022

Comments

  • Lars Holdgaard
    Lars Holdgaard almost 2 years

    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.<---
    
    ===================
    
  • Joel McBeth
    Joel McBeth over 5 years
    As an additional point: I installed the node.js tools from the visual studio installer and continued to get this error and assumed it must have been installed and there is something else going on. Well, it still wasn't installed. I couldn't find it anywhere on my computer and it didn't work until I downloaded and installed node.js from the website and restarted my computer.
  • iltaf khalid
    iltaf khalid over 5 years
    I had the same issue as I had installed Node while Visual Studio was open. I then restarted VS and everything worked fine.
  • Tman
    Tman over 3 years
    This worked for me. I downloaded it here: nodejs.org/en instead of using the package manager.
  • afruzan
    afruzan almost 3 years
    I had the same issue even after dowloading and installing nodejs. my problem solved after restarting visual studio thanks to @iltafkhalid.