问题描述
我一直在尝试使用 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
构建了应用程序.
I built the app using @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]
通常是由导致 not found
错误的依赖关系问题引起的.
ISSUE:The ERROR: (gcloud.app.deploy) Error Response: [9]
is typically caused by a dependency issue that results in an error of not found
.
这个类似的问题,或 sh: 1: ng: 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 项目将包含根 package.json
文件和 devDependencies 部分,如下例所示:
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 start 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
文件需要以下设置:(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
这篇关于在 Google Cloud 上部署 Angular2 应用时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!