【问题标题】:Deploy angular 6 in Azure在 Azure 中部署 Angular 6
【发布时间】:2018-11-13 23:26:15
【问题描述】:

我正在尝试在 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

【问题讨论】:

  • 如果你正在复制dist目录中的构建文件(这是一件好事),你不需要src目录中的那些,也不需要调用ng serve--你只需要从dist访问index.html
  • @user184994 我更新了我的徽标。我运行“ng build prod”命令在 dist 文件夹中生成文件。这是我的 package.json ` { "name": "poc-pwa-angular-v2", "version": "0.0.0", "scripts": { "ng": "ng", "start": " ng serve","build":"ng build","test":"ng test","lint":"ng lint","e2e":"ng e2e","postinstall":"npm run build" } ,`
  • 是的,你还在打电话给ng serve 看那个错误信息。您无需致电ng serve-- 这仅用于本地开发。您只需提供dist 目录中的文件
  • @user184994 感谢您的澄清,在这种情况下,我从 package.json 中删除了“脚本”块并再次上升,它工作了

标签: javascript angular azure azure-devops devops


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    感谢您的宝贵时间,在这种情况下,我删除了 package.json 脚本块并再次上去,它工作了。

    ...
    "version": "0.0.0",
      "scripts": {
      },
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-17
      • 2018-07-08
      • 1970-01-01
      • 2018-12-15
      • 2019-04-28
      • 1970-01-01
      • 1970-01-01
      • 2019-02-18
      相关资源
      最近更新 更多