Angular应用程序部署到Azure-无法启动npm

时间:2018-10-01 15:11:33

标签: node.js angular azure npm

我正在尝试将Angular应用程序部署到Azure。虽然我可以使用Azure成功发布应用程序,但在访问发布的网站时会收到以下错误消息:

AggregateException: One or more errors occurred. (One or more errors occurred. (Failed to start 'npm'. To resolve this:.

    [1] Ensure that 'npm' is installed and can be found in one of the PATH directories.
    Current PATH enviroment variable is: D:\Program Files (x86)\nodejs;D:\Windows\system32;D:\Windows;D:\Windows\System32\Wbem;D:\Windows\System32\WindowsPowerShell\v1.0\;D:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;;D:\Program Files (x86)\dotnet;D:\Program Files\Git\cmd;D:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;D:\Program Files (x86)\PHP\v5.6;D:\Python27;
    Make sure the executable is in one of those directories, or update your PATH.

我当前的应用程序目录已经使用了node(npm)版本8.11.3,因此我不确定为什么我的应用程序似乎找不到它。

有人可以帮我指出正确的方向来解决这个问题吗?我是Azure新手。

非常感谢。

2 个答案:

答案 0 :(得分:0)

App Service默认情况下不运行Node app。确保在“应用程序设置”中指定了“ WEBSITE_NODE_DEFAULT_VERSION”参数,该参数指向正确版本的Node.js。完成后重新启动应用。

答案 1 :(得分:0)

您是否在.csproj中使用In Process托管模型:

<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>

根据issue,这可能会导致Angular SPA出现问题。

有解决此问题的方法:

  

我们添加了一个帮助程序,以将当前目录设置为2.2(https://github.com/aspnet/Docs/blob/master/aspnetcore/host-and-deploy/aspnet-core-module/samples_snapshot/2.x/CurrentDirectoryHelpers.cs)中的正确值,只需将CurrentDirectoryHelpers.SetCurrentDirectory()作为Program.cs的第一行即可。我们还将开始在3.0中默认将当前目录设置为正确的值。