首页 > 解决方案 > 在 Azure 中部署 Angular 6

问题描述

我正在尝试在 azure 门户上部署示例应用程序,但遇到了一些困难。

起初我只是在测试,所以我用 ng new poc-pwa-angular-v2 创建了一个 Angular 应用程序。之后,我去了一个 Bitbucket 存储库。

在 Azure 中,我创建了一个 Web 应用程序,并在部署选项中连接了 bitbucket 并设置了我的主分支。

我尝试使用 kudu(deploy.cmd 和 .deployment)生成脚本,但在第一次部署时出现错误。

任何人都可以给小费吗?

看我的日志。

Command: deploy.cmd
Handling node.js deployment.
Creating app_offline.htm
KuduSync.NET from: 'D:\home\site\repository' to: 'D:\home\site\wwwroot'
Copying file: 'package.json'
Deleting app_offline.htm
Invalid start-up command "ng serve" in package.json. Please use the format "node <script relative path>".
Looking for app.js/server.js under site root.
Missing server.js/app.js files, web.config is not generated
The package.json file does not specify node.js engine version constraints.
The node.js application will run with the default node.js version 10.6.0.
Selected npm version 6.1.0

> poc-pwa-angular-v2@0.0.0 postinstall D:\home\site\wwwroot
> npm run build


> poc-pwa-angular-v2@0.0.0 build D:\home\site\wwwroot
> ng build

'ng' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! poc-pwa-angular-v2@0.0.0 build: `ng build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the poc-pwa-angular-v2@0.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     D:\local\AppData\npm-cache\_logs\2018-11-13T22_16_35_989Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! poc-pwa-angular-v2@0.0.0 postinstall: `npm run build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the poc-pwa-angular-v2@0.0.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
Failed exitCode=1, command="D:\Program Files (x86)\nodejs\10.6.0\node.exe" "D:\Program Files (x86)\npm\6.1.0\node_modules\npm\bin\npm-cli.js" install --production
npm ERR!     D:\local\AppData\npm-cache\_logs\2018-11-13T22_16_36_053Z-debug.log
An error has occurred during web site deployment.
Invalid start-up command "ng serve" in package.json. Please use the format "node <script relative path>".\r\nMissing server.js/app.js files, web.config is not generated\r\n'ng' is not recognized as an internal or external command,\r\noperable program or batch file.\r\nnpm ERR! code ELIFECYCLE\r\nnpm ERR! errno 1\r\nnpm ERR! poc-pwa-angular-v2@0.0.0 build: `ng build`\r\nnpm ERR! Exit status 1\r\nnpm ERR! \r\nnpm ERR! Failed at the poc-pwa-angular-v2@0.0.0 build script.\r\nnpm ERR! This is probably not a problem with npm. There is likely additional logging output above.\r\n\r\nnpm ERR! A complete log of this run can be found in:\r\nnpm ERR!     D:\local\AppData\npm-cache\_logs\2018-11-13T22_16_35_989Z-debug.log\r\nnpm ERR! code ELIFECYCLE\r\nnpm ERR! errno 1\r\nnpm ERR! poc-pwa-angular-v2@0.0.0 postinstall: `npm run build`\r\nnpm ERR! Exit status 1\r\nnpm ERR! \r\nnpm ERR! Failed at the poc-pwa-angular-v2@0.0.0 postinstall script.\r\nnpm ERR! This is probably not a problem with npm. There is likely additional logging output above.\r\n\r\nnpm ERR! A complete log of this run can be found in:\r\nnpm ERR!     D:\local\AppData\npm-cache\_logs\2018-11-13T22_16_36_053Z-debug.log\r\nD:\Program Files (x86)\SiteExtensions\Kudu\78.11022.3613\bin\Scripts\starter.cmd deploy.cmd

标签: javascriptangularazureazure-devopsdevops

解决方案


问题是未安装 Azure Angular cli。您将需要在ng build本地执行(或作为构建和发布管道的一部分。您还可以使用 Azure DevOps 构建来免费构建 240 分钟)并将其上传到(仅选项):

  1. Azure 应用服务。
  2. 将其上传到 Blob 存储并使用 Azure 函数代理来提供文件。
  3. 如果您需要服务器端渲染,则需要将其作为 NodeJs 应用程序或 .net 应用程序的一部分上传

推荐阅读