我有一个带有React前端的ASP.NET Core解决方案。我现在有一个问题,我无法使用Visual Studio中的正常发布窗口释放代码。我发布到Azure网络应用程序内的一个Web应用程序,它完全适用于我所有其他以相同方式构建的解决方案。
代码在本地完美运行,我可以在本地运行npm install
而不会出现问题。
错误显然来自发布时未找到的某个文件。在我的项目文件中,我一直在调试,发现这是一个挑战:
<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>
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
如果我注释掉前三行(npm install
和两个webpacks),我可以发布解决方案,但显然没有使用JavaScript。
知道如何解决这个问题吗?至少,如何更好地调试它?
Visual Studio中的可视错误:
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.<---
===================
答案 0 :(得分:8)
所以这很令人尴尬但对未来的Google员工有用。
根本问题很简单:它是一台没有安装Node.js
(或NPM
)的新计算机。这使得错误消息非常有用:找不到node
!
解决方案很简单:安装Node.js
,确保它在您的PATH中并重新启动计算机。然后你将解决这个问题。