简体   繁体   English

在部署Angular 2项目时,Azure持续部署失败了Github

[英]Azure Continuous deployment failed with Github when deploying an Angular 2 project

I am completely new to Azure and Angular2. 我是Azure和Angular2的新手。

The Objective 目标

Setup Azure Continuous deployment with GitHub. 使用GitHub设置Azure持续部署。

The Problem 问题

Azure is picking up commits to the main branch on the repository. Azure正在获取存储库主分支的提交。 So this part is OK. 所以这部分还可以。 However, the deployment is failed due to a build error. 但是,由于生成错误,部署失败。

Here is the Deployment Details: 这是部署详细信息:

在此输入图像描述

And here is the complete Log: 这是完整的日志:

Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling .NET Web Application deployment.
MSBuild auto-detection: using msbuild version '14.0' from 'D:\Program Files (x86)\MSBuild\14.0\bin'.
All packages listed in packages.config are already installed.
D:\home\site\repository\LearnJS\LearnJS.Web\app\app.component.ts(1,41): error TS2307: Build: Cannot find module 'angular2/core'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\app.component.ts(2,46): error TS2307: Build: Cannot find module 'angular2/router'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\crisis-form.component.ts(1,25): error TS2307: Build: Cannot find module 'angular2/core'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\crisis-form.component.ts(2,22): error TS2307: Build: Cannot find module 'angular2/common'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\crisis.component.ts(1,33): error TS2307: Build: Cannot find module 'angular2/core'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\crisis.component.ts(2,30): error TS2307: Build: Cannot find module 'angular2/http'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\crisis.service.ts(1,48): error TS2307: Build: Cannot find module 'angular2/core'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\crisis.service.ts(2,55): error TS2307: Build: Cannot find module 'angular2/http'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\crisis.service.ts(4,26): error TS2307: Build: Cannot find module 'rxjs/Observable'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\crisis.service.ts(12,16): error TS2304: Build: Cannot find name 'Promise'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\hero-form.component.ts(1,25): error TS2307: Build: Cannot find module 'angular2/core'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\hero-form.component.ts(2,22): error TS2307: Build: Cannot find module 'angular2/common'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\hero.component.ts(1,33): error TS2307: Build: Cannot find module 'angular2/core'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\hero.component.ts(2,30): error TS2307: Build: Cannot find module 'angular2/http'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\hero.service.ts(1,48): error TS2307: Build: Cannot find module 'angular2/core'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\hero.service.ts(2,55): error TS2307: Build: Cannot find module 'angular2/http'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\hero.service.ts(4,26): error TS2307: Build: Cannot find module 'rxjs/Observable'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\hero.ts(1,18): error TS1148: Build: Cannot compile modules unless the '--module' flag is provided. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\main.ts(1,28): error TS2307: Build: Cannot find module 'angular2/platform/browser'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\main.ts(2,32): error TS2307: Build: Cannot find module 'angular2/router'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
Failed exitCode=1, command="D:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" "D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="D:\local\Temp\8d33697b325b07b";AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release;UseSharedCompilation=false /p:SolutionDir="D:\home\site\repository\LearnJS\\"
An error has occurred during web site deployment.
\r\nC:\Program Files (x86)\SiteExtensions\Kudu\51.50212.2079\bin\scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"

It seems that the build host does not find angular modules. 似乎构建主机没有找到角度模块。 I understand these modules exist in the ./node_modules directory which is NOT checked in to my repository. 我理解这些模块存在于./node_modules目录中,该目录未签入我的存储库。 I do have a package.json file in the repository, which looks like this: 我在存储库中有一个package.json文件,如下所示:

{
  "name": "angular2-quickstart",
  "version": "1.0.0",
  "scripts": {
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lite": "lite-server",
    "start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
  },
  "license": "ISC",
  "dependencies": {
    "angular2": "2.0.0-beta.0",
    "systemjs": "0.19.6",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.0",
    "zone.js": "0.5.10"
  },
  "devDependencies": {
    "concurrently": "^1.0.0",
    "lite-server": "^1.3.4",
    "typescript": "^1.7.5"
  }
}

The Question 问题

What do I need to do to get Azure to pull these node.js modules when deploying the site? 在部署站点时,我需要做什么才能让Azure拉出这些node.js模块?

Should I just check in my node_modules directory? 我应该只检查我的node_modules目录吗? But it seems to be against this question . 但它似乎反对这个问题

Things I have tried 我尝试过的事情

I installed Azure Command Line Interface and tried to run this command as suggested by this post . 我安装了Azure命令行界面,并尝试按照此帖的建议运行此命令。

azure site deploymentscript --node

But I got this error 但我得到了这个错误 在此输入图像描述

Update 2016-02-18: 更新2016-02-18:

Rerun the azure site deploymentscript --node command, which generates two files: .deployment and deploy.cmd . 重新运行azure site deploymentscript --node命令,该命令生成两个文件: .deploymentdeploy.cmd Committed both file into the main branch. 将两个文件都提交到主分支中。 Looking closely on the first line of the log, azure runs a deploy.cmd from this directory 仔细查看日志的第一行,azure从此目录运行deploy.cmd

D:\home\site\deployments\tools\deploy.cmd

Do I need to create a directory deployments\\tools in my project or did I put the deploy.cmd at the wrong place? 我是否需要在项目中创建目录deployments\\tools ,还是将deploy.cmd放在错误的位置? I still got the same build error. 我仍然有相同的构建错误。

Partial log file AFTER checking two deployment files. 检查两个部署文件后的部分日志文件。

Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling .NET Web Application deployment.
MSBuild auto-detection: using msbuild version '14.0' from 'D:\Program Files (x86)\MSBuild\14.0\bin'.
All packages listed in packages.config are already installed.
D:\home\site\repository\LearnJS\LearnJS.Web\app\app.component.ts(1,41): error TS2307: Build: Cannot find module 'angular2/core'. 

Here is the deploy.cmd file: 这是deploy.cmd文件:

    @if "%SCM_TRACE_LEVEL%" NEQ "4" @echo off

:: ----------------------
:: KUDU Deployment Script
:: Version: 1.0.6
:: ----------------------

:: Prerequisites
:: -------------

:: Verify node.js installed
where node 2>nul >nul
IF %ERRORLEVEL% NEQ 0 (
  echo Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment.
  goto error
)

:: Setup
:: -----

setlocal enabledelayedexpansion

SET ARTIFACTS=%~dp0%..\artifacts

IF NOT DEFINED DEPLOYMENT_SOURCE (
  SET DEPLOYMENT_SOURCE=%~dp0%.
)

IF NOT DEFINED DEPLOYMENT_TARGET (
  SET DEPLOYMENT_TARGET=%ARTIFACTS%\wwwroot
)

IF NOT DEFINED NEXT_MANIFEST_PATH (
  SET NEXT_MANIFEST_PATH=%ARTIFACTS%\manifest

  IF NOT DEFINED PREVIOUS_MANIFEST_PATH (
    SET PREVIOUS_MANIFEST_PATH=%ARTIFACTS%\manifest
  )
)

IF NOT DEFINED KUDU_SYNC_CMD (
  :: Install kudu sync
  echo Installing Kudu Sync
  call npm install kudusync -g --silent
  IF !ERRORLEVEL! NEQ 0 goto error

  :: Locally just running "kuduSync" would also work
  SET KUDU_SYNC_CMD=%appdata%\npm\kuduSync.cmd
)
goto Deployment

:: Utility Functions
:: -----------------

:SelectNodeVersion

IF DEFINED KUDU_SELECT_NODE_VERSION_CMD (
  :: The following are done only on Windows Azure Websites environment
  call %KUDU_SELECT_NODE_VERSION_CMD% "%DEPLOYMENT_SOURCE%" "%DEPLOYMENT_TARGET%" "%DEPLOYMENT_TEMP%"
  IF !ERRORLEVEL! NEQ 0 goto error

  IF EXIST "%DEPLOYMENT_TEMP%\__nodeVersion.tmp" (
    SET /p NODE_EXE=<"%DEPLOYMENT_TEMP%\__nodeVersion.tmp"
    IF !ERRORLEVEL! NEQ 0 goto error
  )

  IF EXIST "%DEPLOYMENT_TEMP%\__npmVersion.tmp" (
    SET /p NPM_JS_PATH=<"%DEPLOYMENT_TEMP%\__npmVersion.tmp"
    IF !ERRORLEVEL! NEQ 0 goto error
  )

  IF NOT DEFINED NODE_EXE (
    SET NODE_EXE=node
  )

  SET NPM_CMD="!NODE_EXE!" "!NPM_JS_PATH!"
) ELSE (
  SET NPM_CMD=npm
  SET NODE_EXE=node
)

goto :EOF

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Deployment
:: ----------

:Deployment
echo Handling node.js deployment.

:: 1. KuduSync
IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" (
  call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_SOURCE%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd"
  IF !ERRORLEVEL! NEQ 0 goto error
)

:: 2. Select node version
call :SelectNodeVersion

:: 3. Install npm packages
IF EXIST "%DEPLOYMENT_TARGET%\package.json" (
  pushd "%DEPLOYMENT_TARGET%"
  call :ExecuteCmd !NPM_CMD! install --production
  IF !ERRORLEVEL! NEQ 0 goto error
  popd
)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: Post deployment stub
IF DEFINED POST_DEPLOYMENT_ACTION call "%POST_DEPLOYMENT_ACTION%"
IF !ERRORLEVEL! NEQ 0 goto error

goto end

:: Execute command routine that will echo out when error
:ExecuteCmd
setlocal
set _CMD_=%*
call %_CMD_%
if "%ERRORLEVEL%" NEQ "0" echo Failed exitCode=%ERRORLEVEL%, command=%_CMD_%
exit /b %ERRORLEVEL%

:error
endlocal
echo An error has occurred during web site deployment.
call :exitSetErrorLevel
call :exitFromFunction 2>nul

:exitSetErrorLevel
exit /b 1

:exitFromFunction
()

:end
endlocal
echo Finished successfully.

Based on my understanding, I think your needs was creating a static web project with TypeScript and Angular 2, then deploying the static website into Azure WebApp with Continuous Deployment via GitHub. 根据我的理解,我认为您的需求是使用TypeScript和Angular 2创建静态Web项目,然后通过GitHub将静态网站部署到Azure WebApp并进行持续部署。

The simple way is creating a static web project in VS with nodejs tools, then only developing for these static web HTML page with js files compiled from ts files, then commit them to your created GitHub respository, and set up the continuous deployment from GitHub for Azure WebApp on Azure portal. 简单的方法是使用nodejs工具在VS中创建静态Web项目,然后仅针对使用从ts文件编译的js文件的这些静态Web HTML页面进行开发,然后将它们提交到创建的GitHub存储库,并从GitHub设置持续部署Azure门户上的Azure WebApp。

So I think you can try to refer to the other answered SO thread Deploying Hexo on Azure.. not sure what i'm missing to know how to do it. 所以我认为你可以尝试参考另一个回答SO线程在Azure上部署Hexo ..不知道我错过什么 ,知道如何做到这一点。

The deployment script for Node works, the problem is that you are using it on your harddrive root in a Non-Administrative Command Prompt. Node的部署脚本有效,问题是您在非管理命令提示符的硬盘根上使用它。

Either open the Command Prompt with Administrative rights or run it on a folder where your user has write permission (maybe in your Documents folder). 打开具有管理权限的命令提示符,或在用户具有写入权限的文件夹上运行它(可能在您的Documents文件夹中)。

nodejs部署脚本生成

Add the generated files to your Web app folder. 将生成的文件添加到Web应用程序文件夹中。 You don't need to create a VS .csproj, since it's a client-only application. 您不需要创建VS .csproj,因为它是仅客户端应用程序。

Typescript is among your 'devDependencies', that means that it's running on your Development Environment, it should be compiling the .ts files into .js files. Typescript属于你的'devDependencies',这意味着它在你的开发环境中运行,它应该将.ts文件编译成.js文件。 You should push those compiled .js files to your repo and reference them in your pages. 您应该将那些已编译的.js文件推送到您的仓库并在您的页面中引用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM