【问题标题】:Google Cloud Node js deployment issue : (gcloud.app.deploy) Error Response: [9]Google Cloud Node js 部署问题:(gcloud.app.deploy)错误响应:[9]
【发布时间】:2019-05-22 21:52:03
【问题描述】:
我是 Angular 的新手,我正在尝试构建一个基本的 HelloWorld 程序以部署到 Google Cloud。但是,我得到了如下所示的异常。
这些是我采取的步骤:
- 我已经安装了 NVM,它使用 npm 版本 5.6.0 和 Google Cloud 客户端。
- 我已经使用
ng new 命令创建了HelloWorld 应用程序。
- 在我的项目中,我运行了
ng build --prod 命令。
- 最后,我运行
gcloud app deploy 命令来部署HelloWorld 应用程序。
在所有这些步骤之后,这是我得到的错误:
> my-app@0.0.0 start /app
> ng serve
sh: 1: ng: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! my-app@0.0.0 start: `ng serve`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the my-app@0.0.0 start 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! /root/.npm/_logs/2018-04-24T17_23_25_110Z-debug.log
请建议下一步做什么。
【问题讨论】:
标签:
node.js
angular
google-app-engine
google-cloud-platform
【解决方案1】:
首先安装 angular cli
使用这个命令:npm install -g angular-cli
然后再试一次希望它会工作。
【解决方案2】:
由于您是使用 Angular 的新手,并且您想知道如何将您的 Angular 应用程序部署到 Google Cloud,这里有一个 tutorial 可能对您有所帮助。它包含一个 Angular 应用程序示例,您可以将其用作开发自己的应用程序的参考。以防万一,我还将包含一个example,介绍如何使用 Node.js 部署 HelloWorld 应用程序。
您可以专注于与准备正确设置、测试示例应用程序并将其部署到 Google Cloud 相关的部分。
简单来说,在应用程序的根目录中,应该是app.yaml 等文件,你可以运行以下命令在本地准备和测试你的应用程序:
$ npm install
$ npm start
在 Cloud Shell 中,点击 Web 预览图标(看起来像方形眼睛的图标)并选择“在端口 8080 上预览”以检查测试应用程序是否正常工作。
如果测试成功,下一步是通过运行以下命令将应用程序部署到 Google Cloud:
$ gcloud app deploy
部署完成后,运行以下命令检查部署是否正确:
$ gcloud app browse
它会指向你的应用程序正在运行的地址,并检查部署是否成功。
【解决方案3】:
我在部署过程中遇到了这样的错误,(这是一个 rimraf not found 错误),为了解决这个问题,我只需复制我的 devdependencies 并将其添加到 package.json 文件中的依赖项中。我不知道这是否是正确的做法,但它对我有用!
希望它可以帮助某人