問題描述
將 Nx 工作區部署到 Google App Engine (Deploying Nx workspace to Google App Engine)
我的 Nx 應用在本地運行良好,但部署到 GAE 時失敗並出現以下錯誤:
sh: 1: exec: nx: not found
它找不到 dependencies
下列出的 nx
(不是 devDependencies
),因為 GAE 沒有安裝這些。
我的 package.json
裡面有這個:
"scripts": {
"start": "nx serve api",
所以當 GAE 運行 npm run start
時它會失敗。我嘗試直接指定 nx
的路徑,但嘗試使用 node_modules/nx/bin/nx
來引用它,但這也失敗了。
I'我想知道如何讓 GAE 使用 nx
為應用程序提供服務。
這是一個如此簡單和基本的用例,我很困惑,它沒有一個簡單的解決方案。我一定錯過了一些非常簡單的東西。
參考解法
方法 1:
I am using Nx@13, here are steps to deploy to GAE:
Add
"generatePackageJson": true,
toproduction
executor, it will generate apackage.json
indist/apps/serviceA/package.json
GAE will look for
scripts:{"start:"your way to start nodejs app "}
orserver.js
if thestart
script not found. You will have to write a script to addscripts:{"start:"node main.js"}
into the generatedpackage.json
in #1In
cloudbuild
we will have to execute GAE deploy command indist/apps/serviceA
folder, luckilycloudbuild
step supportsdir
</ol>
cloudbuild.yaml
steps:
‑ name: node:16‑bullseye
entrypoint: npm
args: ['install']
‑ name: node:16‑bullseye
entrypoint: npm
args: ['run', 'lint', '${_SERVICE_NAME}']
‑ name: node:16‑bullseye
entrypoint: npm
args: ['run', 'test', '${_SERVICE_NAME}']
‑ name: node:16‑bullseye
entrypoint: npm
args:
['run', 'build', '${_SERVICE_NAME}', '‑‑', '‑‑configuration=production']
‑ name: node:16‑bullseye
entrypoint: bash
args:
[
'‑c',
'node tools/prepare‑gcp‑app‑engine.js ‑‑serviceName=${_SERVICE_NAME}',
]
‑ name: gcr.io/google.com/cloudsdktool/cloud‑sdk:376.0.0‑slim
dir: dist/apps/${_SERVICE_NAME}
entrypoint: gcloud
args:
‑ app
‑ deploy
‑ app‑engine.yaml
‑ ‑‑version=$SHORT_SHA
‑ ‑‑promote
‑ ‑‑stop‑previous‑version
‑ ‑‑quiet
substitutions:
_SERVICE_NAME: game‑api
(by Nightwolf、vanduc1102)