【发布时间】:2021-04-18 14:10:17
【问题描述】:
我想使用 Google 的 Cloud Build 自动构建我的 nextjs 应用。但是,触发器在推送到我的存储库后会引发错误。
错误信息:
Starting Step #0
Step #0: Already have image (with digest): gcr.io/cloud-builders/npm
Step #0:
Step #0: > next-kara@0.1.0 prepare /workspace
Step #0: > npm run gcp-build
Step #0:
Step #0:
Step #0: > next-kara@0.1.0 gcp-build /workspace
Step #0: > next build
Step #0:
Step #0: sh: 1: next: not found
Step #0: npm ERR! code ELIFECYCLE
Step #0: npm ERR! syscall spawn
Step #0: npm ERR! file sh
Step #0: npm ERR! errno ENOENT
Step #0: npm ERR! next-kara@0.1.0 gcp-build: `next build`
Step #0: npm ERR! spawn ENOENT
Step #0: npm ERR!
Step #0: npm ERR! Failed at the next-kara@0.1.0 gcp-build script.
Step #0: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Step #0: npm WARN Local package.json exists, but node_modules missing, did you mean to install?
Step #0:
Step #0: npm ERR! A complete log of this run can be found in:
Step #0: npm ERR! /builder/home/.npm/_logs/2021-04-18T13_48_44_437Z-debug.log
Step #0: npm ERR! code ELIFECYCLE
Step #0: npm ERR! errno 1
Step #0: npm ERR! next-kara@0.1.0 prepare: `npm run gcp-build`
Step #0: npm ERR! Exit status 1
Step #0: npm ERR!
Step #0: npm ERR! Failed at the next-kara@0.1.0 prepare script.
Step #0: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Step #0: npm WARN Local package.json exists, but node_modules missing, did you mean to install?
Step #0:
Step #0: npm ERR! A complete log of this run can be found in:
Step #0: npm ERR! /builder/home/.npm/_logs/2021-04-18T13_48_44_465Z-debug.log
Finished Step #0
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/npm" failed: step exited with non-zero status: 1
我的 cloudbuild.yaml 文件如下所示:
steps:
- name: "gcr.io/cloud-builders/npm"
args: ["install", "run", "prepare"] # "install added after comment"
- name: "gcr.io/cloud-builders/gcloud"
args: ["app", "deploy", "app.yaml"]
timeout: "1600s"
还有我的 package.json:
{
"name": "next-kara",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"gcp-build": "next build",
"prepare": "npm run gcp-build",
"start": "next start -p $PORT",
"preinstall": "node lock_node_version.js"
}
有什么想法吗?当脚本在本地执行时,该应用在 Google 的 App Engine 上运行良好。
谢谢
更新
正如 cmets 所建议的,我还尝试在更改为节点版本 14.0.0 和 14.10.0(最新版本)时执行触发器。相同的行为;在本地执行该应用在 Google 的 App Engine 上运行,但在使用 Github 触发器执行时出现同样的错误。
将“安装”添加到 cloudbuild.yaml 文件后出错:
Step #0: make: Leaving directory '/workspace/node_modules/contextify/build'
Step #0: gyp ERR! build error
Step #0: gyp ERR! stack Error: `make` failed with exit code: 2
Step #0: gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
Step #0: gyp ERR! stack at ChildProcess.emit (events.js:314:20)
Step #0: gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
Step #0: gyp ERR! System Linux 5.4.0-1040-gcp
Step #0: gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
Step #0: gyp ERR! cwd /workspace/node_modules/contextify
Step #0: gyp ERR! node -v v14.10.0
Step #0: gyp ERR! node-gyp -v v5.1.0
Step #0: gyp ERR! not ok
Step #0: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/watchpack-chokidar2/node_modules/fsevents):
Step #0: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
Step #0: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/fsevents):
Step #0: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
Step #0:
Step #0: npm ERR! code ELIFECYCLE
Step #0: npm ERR! errno 1
Step #0: npm ERR! contextify@0.1.15 install: `node-gyp rebuild`
Step #0: npm ERR! Exit status 1
Step #0: npm ERR!
Step #0: npm ERR! Failed at the contextify@0.1.15 install script.
Step #0: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
【问题讨论】:
-
缺少“npm install”步骤。
-
我会尝试但收到另一个错误(更新了我的问题)。但是为什么当我在本地运行脚本
gcloud app deploy app.yaml不需要额外的 npm install 时需要 npm install 呢? -
npm install 是必需的,因为 node_modules 不是存储库的一部分,在这种情况下不是图像。过程是 1. 提取源 2. 安装依赖项 3. 运行代码 至于你的其他问题主要是由于一些不匹配的依赖项。
node-gyp rebuild删除node_modules并重试 -
你是在 Mac 上开发吗?您的依赖接缝仅与 Mac 兼容
-
@guillaumeblaquiere,我在 Windows 上开发,但我的同事在 Mac 上。似乎 App Engine VM 正在 Linux 上运行。但是,我在 Windows 机器上本地运行应用程序没有问题。
标签: google-app-engine github google-cloud-platform google-cloud-build