【问题标题】:Next.js - ERROR Build directory is not writeable on Google Cloud BuildNext.js - 错误构建目录不可在 Google Cloud Build 上写入
【发布时间】:2020-07-22 21:27:56
【问题描述】:

我试图使用 Cloud Build 将 Next.JS 应用程序的部署过程自动化到 App Engine,但在 build 阶段它一直失败:

Error: > Build directory is not writeable. https://err.sh/vercel/next.js/build-dir-not-writeable

我似乎不知道要解决什么问题。

我当前的构建文件是,它在第​​ 2 步一直失败:

steps:
  # install dependencies
- name: 'gcr.io/cloud-builders/npm'
  args: ['install']
  # build the container image
- name: 'gcr.io/cloud-builders/npm'
  args: ['run', 'build']
  # deploy to app engine
- name: "gcr.io/cloud-builders/gcloud"
  args: ["app", "deploy"]
  env:
  - 'PORT=8080'
  - 'NODE_ENV=production'
timeout: "1600s"

app.yaml:

runtime: nodejs12

handlers:
- url: /.*
  secure: always
  script: auto

env_variables:
  PORT: 8080
  NODE_ENV: 'production'

任何帮助将不胜感激

【问题讨论】:

  • 你的 next.js 版本是什么?
  • 在我的 app.yaml 中,我已将其指定为使用 v12。我注意到我错过了这个,所以把它添加到我上面的帖子中
  • here 是与 EC2 上的 next.js 相关的问题,他们建议为您的项目目录设置权限 - sudo chmod 777 -R /your_project_path

标签: next.js google-cloud-build


【解决方案1】:

升级到下一个版本 9.3.3 后可以重现相同的行为。

原因

如果您使用 gcr.io/cloud-builders/npm,该问题与由 google 管理的 npm 依赖项有关,他们似乎在旧节点版本上的 Google Cloud Build 中运行您的构建。

在这里您可以找到当前支持的版本 https://console.cloud.google.com/gcr/images/cloud-builders/GLOBAL/npm?gcrImageListsize=30

如您所见,Google 的最新节点版本是 10.10。最新的 next.js 版本至少需要 node 10.13

解决方案

gcr.io/cloud-builders/npm 更改为

- name: node
  entrypoint: npm

为了使用在 node12 上运行的官方 docker npm 包。 在这些更改之后,您的构建将再次成功。

旁注

切换到官方 npm 会增加构建持续时间(至少在我的情况下)。它比 gcr npm 需要大约 2 分钟。

【讨论】:

  • 非常感谢!解决了它。我宁愿延迟 2 分钟,然后不得不手动执行我一直坚持的部署哈哈
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-26
  • 2020-09-16
  • 2019-03-07
  • 2019-03-20
  • 1970-01-01
  • 2020-07-03
相关资源
最近更新 更多