在Google Cloud上部署Angular2应用程序时出错 [英] Error deploying Angular2 app on Google Cloud

查看:64
本文介绍了在Google Cloud上部署Angular2应用程序时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用Google App Engine部署Angular2应用程序,并且遇到了问题.尝试部署时收到以下错误:

I have been attempting to deploy an Angular2 application with Google App Engine and have been running into issues. I get the following error when trying to deploy:

Updating service [default]...failed.                                                                                                          
ERROR: (gcloud.app.deploy) Error Response: [9] 
Application startup error:
yarn start v0.21.3
$ ng serve 
** NG Live Development Server is running on http://localhost:8080 **
 52% building modules 357/395 modules 38 active .../position/overlay-position-builder.js

在给定行 .../position/overlay-position-builder.js 的情况下,错误似乎指向 @ angular/material .

The error seems to point to @angular/material given the line .../position/overlay-position-builder.js.

我使用 @ angular-cli 构建了该应用.

我看到的日志中没有任何有价值的东西.

There is nothing of value in the logs that I can see.

关于这个问题可能是什么以及如何解决这个问题的任何想法?

Any ideas on what the issue might be and how to resolve this?

推荐答案

问题: ERROR:(gcloud.app.deploy)错误响应:[9] 通常是由依赖项问题引起的,该依赖关系问题导致未找到 的错误.

ISSUE: The ERROR: (gcloud.app.deploy) Error Response: [9] is typically caused by a dependency issue that results in an error of not found.

已经通过使用创建Dockerfile

This similar issue, or sh: 1: ng: not found, has been reported and worked-around by using creating a Dockerfile here.

在此原始帖子中,似乎出现了 yarn start v0.21.3 的问题.

In this original post, it appears that yarn start v0.21.3 is the issue.

解决方案:通过使用angular-cli创建的Angular2项目将包含带有devDependencies部分的根 package.json 文件,如下例所示:

SOLUTION: An Angular2 project created by using the angular-cli will contain the root package.json file with a devDependencies section like the example below:

"devDependencies": {
   "@angular/cli": "1.4.2",
   ...
   ...
},

注意::要获取其他任何依赖性,例如 @ angular/material yarn之类的命令,请启动v0.21.3 . Dockerfile 必须包含用于通过命令行安装这些依赖项的命令.

NOTE: To get any other dependencies, like @angular/material and commands like yarn start v0.21.3 to work. The Dockerfile must include the commands to install those dependencies via command line.

在package.json文件的相同路径内创建一个 app.yaml Dockerfile ,如下例所示:

Create an app.yaml and Dockerfile within the same path of the package.json file like the example below:

angular2-example-app
├── e2e
├── node_modules
├── src
├── package.json
├── app.yaml 
├── Dockerfile

app.yaml 文件将需要以下设置:(

The app.yaml file will need the following settings: (app.yaml documentation):

# [start app_yaml]
  runtime: custom
  env: flex

Dockerfile 将需要用户可以在命令行上调用的所有命令来组装映像.

The Dockerfile will need all the commands a user could call on the command line to assemble an image.

注意: npm install -g @ angular/cli 命令在以下示例中运行:

Note: npm install -g @angular/cli command being ran in the example below:

FROM alpine:latest
MAINTAINER yourname

# update alpine linux
RUN apk update && apk upgrade && \ 
    apk add nodejs && \
    # may comment this line in my computer.
    apk add nodejs-npm && \
    npm install -g @angular/cli

# add source code to images
ADD . /angular2-example-app

# switch working directory
WORKDIR /angular2-example-app

# install dependencies
RUN npm install

# expose port 4200
EXPOSE 4200 

# run ng serve on localhost
CMD ["ng","serve", "--host", "0.0.0.0", "--disable-host-check"] 

将应用程序部署到您的Google Cloud App Engine: gcloud app deploy

Deploy the app to your google cloud App Engine: gcloud app deploy

( gcloud文档)

这篇关于在Google Cloud上部署Angular2应用程序时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆