node.js - Angular 5 不会部署到 Azure 应用服务

标签 node.js angular azure

我们正在尝试将 Angular 5.1.3 应用程序部署到 Azure 应用程序服务。部署由对 GitHub 存储库的提交触发。每次我们部署部署都会花费几分钟,然后会出现以下消息

任何人都可以帮助找出根本问题吗?

ERROR in ./ClientApp/boot.browser.ts
    Module not found : error : Can't resolve './../$$_gendir/ClientApp/app/app.browser.module.ngfactory' in 'D:\home\site\repository\Operations\ClientApp' [D:\home\site\repository\Operations\STB_Operations.csproj]
           @ ./ClientApp/boot.browser.ts 6:0-95

    EXEC : ERROR in error : Please update @angular/cli. Angular 5+ requires at least Angular CLI 1.5+ [D:\home\site\repository\Operations\STB_Operations.csproj]
              at throwNotSupportedError (D:\home\site\repository\Operations\packages\compiler-cli\src\ngtools_api.ts:132:9)
              at Function.NgTools_InternalApi_NG_2.codeGen (D:\home\site\repository\Operations\packages\compiler-cli\src\ngtools_api.ts:80:11)
              at _donePromise.Promise.resolve.then (D:\home\site\repository\Operations\node_modules\@ngtools\webpack\src\plugin.js:430:58)
              at process._tickCallback (internal/process/next_tick.js:103:7)
              at Module.runMain (module.js:606:11)
              at run (bootstrap_node.js:394:7)
              at startup (bootstrap_node.js:149:9)
              at bootstrap_node.js:509:3
      Child
          Hash: 04a987447071d4f6074c
          Time: 23130ms
                   Asset     Size  Chunks                    Chunk Names
          main-server.js  3.29 MB       0  [emitted]  [big]  main-server

          ERROR in ./ClientApp/boot.server.ts
    Module not found : error : Can't resolve './../$$_gendir/ClientApp/app/app.server.module.ngfactory' in 'D:\home\site\repository\Operations\ClientApp' [D:\home\site\repository\Operations\STB_Operations.csproj]
           @ ./ClientApp/boot.server.ts 8:0-94

    EXEC : ERROR in error : Please update @angular/cli. Angular 5+ requires at least Angular CLI 1.5+ [D:\home\site\repository\Operations\STB_Operations.csproj]
              at throwNotSupportedError (D:\home\site\repository\Operations\packages\compiler-cli\src\ngtools_api.ts:132:9)
              at Function.NgTools_InternalApi_NG_2.codeGen (D:\home\site\repository\Operations\packages\compiler-cli\src\ngtools_api.ts:80:11)
              at _donePromise.Promise.resolve.then (D:\home\site\repository\Operations\node_modules\@ngtools\webpack\src\plugin.js:430:58)
              at process._tickCallback (internal/process/next_tick.js:103:7)
              at Module.runMain (module.js:606:11)
              at run (bootstrap_node.js:394:7)
              at startup (bootstrap_node.js:149:9)
              at bootstrap_node.js:509:3
    D:\home\site\repository\Operations\STB_Operations.csproj(117,5): error MSB3073: The command "node node_modules/webpack/bin/webpack.js --env.prod" exited with code 2.
    Failed exitCode=1, command=dotnet publish "D:\home\site\repository\Operations\STB_Operations.csproj" --output "D:\local\Temp\8d555638ef9d872" --configuration Release
    An error has occurred during web site deployment.
    \r\nD:\Program Files (x86)\SiteExtensions\Kudu\70.10102.3204\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"

对于上下文,这是我们的package.json 文件

{
  "name": "STB_Operations",
  "private": true,
  "version": "1.0.0",
  "scripts": {
    "test": "karma start ClientApp/test/karma.conf.js"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^5.1.3",
    "@types/chai": "^4.1.0",
    "@types/jasmine": "^2.8.3",
    "jasmine-core": "^2.8.0",
    "karma": "^2.0.0",
    "karma-chai": "^0.1.0",
    "karma-chrome-launcher": "^2.2.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.1.1",
    "karma-webpack": "^2.0.8"
  },
  "dependencies": {
    "@angular/animations": "^5.1.3",
    "@angular/common": "^5.1.3",
    "@angular/compiler": "^5.1.3",
    "@angular/core": "^5.1.3",
    "@angular/forms": "^5.1.3",
    "@angular/http": "^5.1.3",
    "@angular/platform-browser": "^5.1.3",
    "@angular/platform-browser-dynamic": "^5.1.3",
    "@angular/platform-server": "^5.1.3",
    "@angular/router": "^5.1.3",
    "@angular/tsc-wrapped": "^4.4.6",
    "@ngtools/webpack": "^1.9.3",
    "@types/webpack-env": "^1.13.3",
    "ajv": "^5.5.2",
    "angular2-router-loader": "^0.3.5",
    "angular2-template-loader": "^0.6.2",
    "aspnet-prerendering": "^3.0.1",
    "aspnet-webpack": "^2.0.1",
    "awesome-typescript-loader": "^3.4.1",
    "bootstrap": "^3.3.7",
    "chai": "^4.1.2",
    "core-js": "^2.5.3",
    "css": "^2.2.1",
    "css-loader": "^0.28.8",
    "es6-promise": "^4.2.2",
    "es6-shim": "^0.35.3",
    "event-source-polyfill": "0.0.12",
    "expose-loader": "^0.7.4",
    "extract-text-webpack-plugin": "^3.0.2",
    "file-loader": "^1.1.6",
    "html-loader": "^0.5.4",
    "isomorphic-fetch": "^2.2.1",
    "jquery": "^3.2.1",
    "json-loader": "^0.5.7",
    "less": "^2.7.3",
    "less-loader": "^4.0.5",
    "log4js": "^2.4.1",
    "preboot": "^5.1.7",
    "raw-loader": "^0.5.1",
    "reflect-metadata": "^0.1.10",
    "rxjs": "^5.5.6",
    "style-loader": "^0.19.1",
    "to-string-loader": "^1.1.5",
    "tslib": "^1.8.1",
    "typescript": "^2.6.2",
    "url-loader": "^0.6.2",
    "webpack": "^3.10.0",
    "webpack-hot-middleware": "^2.21.0",
    "webpack-merge": "^4.1.1",
    "zone.js": "^0.8.19"
  }
}

这是部署脚本(如果它是问题的一部分)

#!/bin/bash

# ----------------------
# KUDU Deployment Script
# Version: 0.2.2
# ----------------------

# Helpers
# -------

exitWithMessageOnError () {
  if [ ! $? -eq 0 ]; then
    echo "An error has occurred during web site deployment."
    echo $1
    exit 1
  fi
}

# Prerequisites
# -------------

# Verify node.js installed
hash node 2>/dev/null
exitWithMessageOnError "Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment."

# Setup
# -----

SCRIPT_DIR="${BASH_SOURCE[0]%\\*}"
SCRIPT_DIR="${SCRIPT_DIR%/*}"
ARTIFACTS=$SCRIPT_DIR/../artifacts
KUDU_SYNC_CMD=${KUDU_SYNC_CMD//\"}

if [[ ! -n "$DEPLOYMENT_SOURCE" ]]; then
  DEPLOYMENT_SOURCE=$SCRIPT_DIR
fi

if [[ ! -n "$NEXT_MANIFEST_PATH" ]]; then
  NEXT_MANIFEST_PATH=$ARTIFACTS/manifest

  if [[ ! -n "$PREVIOUS_MANIFEST_PATH" ]]; then
    PREVIOUS_MANIFEST_PATH=$NEXT_MANIFEST_PATH
  fi
fi

if [[ ! -n "$DEPLOYMENT_TARGET" ]]; then
  DEPLOYMENT_TARGET=$ARTIFACTS/wwwroot
else
  KUDU_SERVICE=true
fi

if [[ ! -n "$KUDU_SYNC_CMD" ]]; then
  # Install kudu sync
  echo Installing Kudu Sync
  npm install kudusync -g --silent
  exitWithMessageOnError "npm failed"

  if [[ ! -n "$KUDU_SERVICE" ]]; then
    # In case we are running locally this is the correct location of kuduSync
    KUDU_SYNC_CMD=kuduSync
  else
    # In case we are running on kudu service this is the correct location of kuduSync
    KUDU_SYNC_CMD=$APPDATA/npm/node_modules/kuduSync/bin/kuduSync
  fi
fi

# Node Helpers
# ------------

selectNodeVersion () {
  if [[ -n "$KUDU_SELECT_NODE_VERSION_CMD" ]]; then
    SELECT_NODE_VERSION="$KUDU_SELECT_NODE_VERSION_CMD \"$DEPLOYMENT_SOURCE\" \"$DEPLOYMENT_TARGET\" \"$DEPLOYMENT_TEMP\""
    eval $SELECT_NODE_VERSION
    exitWithMessageOnError "select node version failed"

    if [[ -e "$DEPLOYMENT_TEMP/__nodeVersion.tmp" ]]; then
      NODE_EXE=`cat "$DEPLOYMENT_TEMP/__nodeVersion.tmp"`
      exitWithMessageOnError "getting node version failed"
    fi

    if [[ -e "$DEPLOYMENT_TEMP/.tmp" ]]; then
      NPM_JS_PATH=`cat "$DEPLOYMENT_TEMP/__npmVersion.tmp"`
      exitWithMessageOnError "getting npm version failed"
    fi

    if [[ ! -n "$NODE_EXE" ]]; then
      NODE_EXE=node
    fi

    NPM_CMD="\"$NODE_EXE\" \"$NPM_JS_PATH\""
  else
    NPM_CMD=npm
    NODE_EXE=node
  fi
}

##################################################################################################################################
# Deployment
# ----------

echo Handling node.js deployment.

# 1. KuduSync
if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then
  "$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh"
  exitWithMessageOnError "Kudu Sync failed"
fi

# 2. Select node version
selectNodeVersion

# 3. Install NPM packages
if [ -e "$DEPLOYMENT_TARGET/package.json" ]; then
  cd "$DEPLOYMENT_TARGET"
  eval $NPM_CMD install --production
  eval $NPM_CMD install --only=dev
  exitWithMessageOnError "npm failed"
  cd - > /dev/null
fi

# 4. Angular Prod Build
if [ -e "$DEPLOYMENT_TARGET/.angular-cli.json" ]; then
  cd "$DEPLOYMENT_TARGET"
  eval ./node_modules/.bin/ng build --prod
  exitWithMessageOnError "Angular build failed"
  cd - > /dev/null
fi

##################################################################################################################################

# Post deployment stub
if [[ -n "$POST_DEPLOYMENT_ACTION" ]]; then
  POST_DEPLOYMENT_ACTION=${POST_DEPLOYMENT_ACTION//\"}
  cd "${POST_DEPLOYMENT_ACTION_DIR%\\*}"
  "$POST_DEPLOYMENT_ACTION"
  exitWithMessageOnError "post deployment action failed"
fi

echo "Finished successfully."

最佳答案

根据错误消息:

ERROR in error : Please update @angular/cli. Angular 5+ requires at least Angular CLI 1.5+

您可能需要添加对开发依赖项的@angular/cli引用:

"@angular/cli": "1.6.3"

并全局安装它:

npm install -g @angular/cli

关于node.js - Angular 5 不会部署到 Azure 应用服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48133363/

相关文章:

mysql - node.js和mysql连接池不导出

node.js - 如何在node.js中设置超时?

css - 在清晰度数据网格单元格中居中内容

azure - 错误 :The deployment parameters are using case sensitive names. 错误参数名称 : name.(ARM 模板部署)

javascript - 我是否必须在单独的文件中定义不同的 mongodb 模型?

angular - 如何以 Angular 禁用模板驱动表单中的所有字段

node.js - 以字符串形式读取angular2中的静态文件

c# - Azure Functions 图像调整大小内容类型

azure - 为什么我的 Azure Function 配置中需要 APPINSIGHTS_INSTRUMENTATIONKEY 和 APPLICATIONINSIGHTS_CONNECTION_STRING?

javascript - 在 Node.js 中包含单独的路由文件