【问题标题】:Google Cloud Build throws errror with NPMGoogle Cloud Build 使用 NPM 引发错误
【发布时间】: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


【解决方案1】:

fsevent 1 和 nodeJS 14 存在问题

我建议您从解决此问题开始,并在本地环境中使用相同版本的 NodeJS。最新cloud builder npm container is node-14 by default(latest)

【讨论】:

  • 您好,我在本地安装了 14.0.0 和 14.10.0(最新版本)并再次尝试触发。但是,我收到了同样的错误 - IMO 似乎 fsevent 不是错误的原因。与 node-gyp 重建相关的 contextify 看起来像是原因......
  • 在使用nodejs14之前在本地使用的是哪个版本?您是否尝试过使用 nodejs12 并使其在本地工作?这似乎是与与软件包而不是 Cloud Build 冲突的 Node 版本相关的问题,因此我建议您在使用 Cloud Build 之前测试本地旧版本,直到您使其工作正如@guillaume 提到的那样,问题出在 nodejs 14 上,所以我不明白为什么要升级到那个版本
猜你喜欢
  • 2020-06-18
  • 2020-12-03
  • 2020-11-29
  • 1970-01-01
  • 2021-03-03
  • 2021-01-20
  • 2019-12-02
  • 2021-01-13
  • 2017-08-01
相关资源
最近更新 更多