`gatsby build` 在本地工作,但不能在 netlify CMS 上工作
`gatsby build` works locally, but not on netlify CMS
我正在部署一个 netlify cms 原型来试验 netlify cms 提供的 blog/markdown 功能。但是,我的构建失败了(尽管 gatsby build
在本地工作)。我已经看到 exit code 127
是一个很常见的错误,但我已经清除了我的 gatsby/netlify 缓存,尝试切换到 npm run build
以获得更全面的错误列表(没有工作,只是在我的终端中继续打印 > blog@1.0.0 build > npm run build
)。我不确定这是否可能是由于依赖性问题造成的,因为我必须使用 --legacy-peer-deps
.
安装插件
这是我的部署日志和 link 我的存储库:https://github.com/claudiahleung/gatsby-learnings。非常感谢任何帮助!
12:02:11 PM: Build ready to start
12:08:45 PM: build-image version: 7b53c5fc4445e3ec99d3949e5d1174a8c5be4f16
12:08:45 PM: build-image tag: v3.7.2
12:08:45 PM: buildbot version: a8df6d1263bb5bcc16f7b4ebb8e9a6cb904cfa8a
12:08:45 PM: Fetching cached dependencies
12:08:45 PM: Failed to fetch cache, continuing with build
12:08:45 PM: Starting to prepare the repo for build
12:08:46 PM: No cached dependencies found. Cloning fresh repo
12:08:46 PM: git clone https://github.com/claudiahleung/gatsby-learnings
12:09:02 PM: Preparing Git Reference refs/heads/main
12:09:04 PM: Parsing package.json dependencies
12:09:05 PM: Starting build script
12:09:05 PM: Installing dependencies
12:09:05 PM: Python version set to 2.7
12:09:06 PM: v12.18.0 is already installed.
12:09:07 PM: Now using node v12.18.0 (npm v6.14.4)
12:09:07 PM: Started restoring cached build plugins
12:09:07 PM: Finished restoring cached build plugins
12:09:07 PM: Attempting ruby version 2.7.1, read from environment
12:09:08 PM: Using ruby version 2.7.1
12:09:08 PM: Using PHP version 5.6
12:09:08 PM: Started restoring cached go cache
12:09:08 PM: Finished restoring cached go cache
12:09:09 PM: go version go1.14.4 linux/amd64
12:09:09 PM: go version go1.14.4 linux/amd64
12:09:09 PM: Installing missing commands
12:09:09 PM: Verify run directory
12:09:10 PM:
12:09:10 PM: ────────────────────────────────────────────────────────────────
12:09:10 PM: Netlify Build
12:09:10 PM: ────────────────────────────────────────────────────────────────
12:09:10 PM:
12:09:10 PM: ❯ Version
12:09:10 PM: @netlify/build 11.3.2
12:09:10 PM:
12:09:10 PM: ❯ Flags
12:09:10 PM: deployId: 608a2fc31e2066000802ecfa
12:09:10 PM:
12:09:10 PM: ❯ Current directory
12:09:10 PM: /opt/build/repo
12:09:10 PM:
12:09:10 PM: ❯ Config file
12:09:10 PM: No config file was defined: using default values.
12:09:10 PM:
12:09:10 PM: ❯ Context
12:09:10 PM: production
12:09:10 PM:
12:09:10 PM: ────────────────────────────────────────────────────────────────
12:09:10 PM: 1. Build command from Netlify app
12:09:10 PM: ────────────────────────────────────────────────────────────────
12:09:10 PM:
12:09:10 PM: $ gatsby build
12:09:10 PM: bash: gatsby: command not found
12:09:10 PM:
12:09:10 PM: ────────────────────────────────────────────────────────────────
12:09:10 PM: "build.command" failed
12:09:10 PM: ────────────────────────────────────────────────────────────────
12:09:10 PM:
12:09:10 PM: Error message
12:09:10 PM: Command failed with exit code 127: gatsby build
12:09:10 PM:
12:09:10 PM: Error location
12:09:10 PM: In Build command from Netlify app:
12:09:10 PM: gatsby build
12:09:10 PM:
12:09:10 PM: Resolved config
12:09:10 PM: build:
12:09:10 PM: command: gatsby build
12:09:10 PM: commandOrigin: ui
12:09:10 PM: publish: /opt/build/repo/public
12:09:11 PM: Caching artifacts
12:09:11 PM: Started saving build plugins
12:09:11 PM: Finished saving build plugins
12:09:11 PM: Started saving pip cache
12:09:11 PM: Finished saving pip cache
12:09:11 PM: Started saving emacs cask dependencies
12:09:11 PM: Finished saving emacs cask dependencies
12:09:11 PM: Started saving maven dependencies
12:09:11 PM: Finished saving maven dependencies
12:09:11 PM: Started saving boot dependencies
12:09:11 PM: Finished saving boot dependencies
12:09:11 PM: Started saving rust rustup cache
12:09:11 PM: Finished saving rust rustup cache
12:09:11 PM: Started saving go dependencies
12:09:11 PM: Finished saving go dependencies
12:09:13 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
12:09:13 PM: Creating deploy upload records
12:09:13 PM: Failing build: Failed to build site
12:09:13 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
12:09:13 PM: Finished processing build request in 28.232494224s
此问题通常与导致此输出的本地环境和 Netlify 环境之间的依赖关系不匹配有关。
尝试将您的 package.json
(如果是,在您的 Netlify 的仪表板中)命令更改为:
"build": "npm run build",
如果您在本地看到很多关于对等依赖项的警告,那么您将需要安装它们,因为 migration guide shows。
另一个可能对您有帮助的解决方法是使用 .nvmrc
文件修复您的 Node 版本。 运行:
node -v > .nvmrc
这将在项目的根目录中创建一个 .nvmrc
文件,其中包含 Node 版本 (node -v
)。 Netlify 在构建您的站点时将使用该文件来设置 Node 环境,如 docs 指出的那样。这在尝试调试某些问题的根源时非常有用。
此外,不要上传(尽快删除它并在 .gitignore
中忽略它)您的存储库中的 .cache
文件夹。你不想保留它,它会在你的回购中 pulling/pushing 东西时节省你的时间(如果其他人在你的项目中工作,可能会避免冲突)。
我正在部署一个 netlify cms 原型来试验 netlify cms 提供的 blog/markdown 功能。但是,我的构建失败了(尽管 gatsby build
在本地工作)。我已经看到 exit code 127
是一个很常见的错误,但我已经清除了我的 gatsby/netlify 缓存,尝试切换到 npm run build
以获得更全面的错误列表(没有工作,只是在我的终端中继续打印 > blog@1.0.0 build > npm run build
)。我不确定这是否可能是由于依赖性问题造成的,因为我必须使用 --legacy-peer-deps
.
这是我的部署日志和 link 我的存储库:https://github.com/claudiahleung/gatsby-learnings。非常感谢任何帮助!
12:02:11 PM: Build ready to start
12:08:45 PM: build-image version: 7b53c5fc4445e3ec99d3949e5d1174a8c5be4f16
12:08:45 PM: build-image tag: v3.7.2
12:08:45 PM: buildbot version: a8df6d1263bb5bcc16f7b4ebb8e9a6cb904cfa8a
12:08:45 PM: Fetching cached dependencies
12:08:45 PM: Failed to fetch cache, continuing with build
12:08:45 PM: Starting to prepare the repo for build
12:08:46 PM: No cached dependencies found. Cloning fresh repo
12:08:46 PM: git clone https://github.com/claudiahleung/gatsby-learnings
12:09:02 PM: Preparing Git Reference refs/heads/main
12:09:04 PM: Parsing package.json dependencies
12:09:05 PM: Starting build script
12:09:05 PM: Installing dependencies
12:09:05 PM: Python version set to 2.7
12:09:06 PM: v12.18.0 is already installed.
12:09:07 PM: Now using node v12.18.0 (npm v6.14.4)
12:09:07 PM: Started restoring cached build plugins
12:09:07 PM: Finished restoring cached build plugins
12:09:07 PM: Attempting ruby version 2.7.1, read from environment
12:09:08 PM: Using ruby version 2.7.1
12:09:08 PM: Using PHP version 5.6
12:09:08 PM: Started restoring cached go cache
12:09:08 PM: Finished restoring cached go cache
12:09:09 PM: go version go1.14.4 linux/amd64
12:09:09 PM: go version go1.14.4 linux/amd64
12:09:09 PM: Installing missing commands
12:09:09 PM: Verify run directory
12:09:10 PM:
12:09:10 PM: ────────────────────────────────────────────────────────────────
12:09:10 PM: Netlify Build
12:09:10 PM: ────────────────────────────────────────────────────────────────
12:09:10 PM:
12:09:10 PM: ❯ Version
12:09:10 PM: @netlify/build 11.3.2
12:09:10 PM:
12:09:10 PM: ❯ Flags
12:09:10 PM: deployId: 608a2fc31e2066000802ecfa
12:09:10 PM:
12:09:10 PM: ❯ Current directory
12:09:10 PM: /opt/build/repo
12:09:10 PM:
12:09:10 PM: ❯ Config file
12:09:10 PM: No config file was defined: using default values.
12:09:10 PM:
12:09:10 PM: ❯ Context
12:09:10 PM: production
12:09:10 PM:
12:09:10 PM: ────────────────────────────────────────────────────────────────
12:09:10 PM: 1. Build command from Netlify app
12:09:10 PM: ────────────────────────────────────────────────────────────────
12:09:10 PM:
12:09:10 PM: $ gatsby build
12:09:10 PM: bash: gatsby: command not found
12:09:10 PM:
12:09:10 PM: ────────────────────────────────────────────────────────────────
12:09:10 PM: "build.command" failed
12:09:10 PM: ────────────────────────────────────────────────────────────────
12:09:10 PM:
12:09:10 PM: Error message
12:09:10 PM: Command failed with exit code 127: gatsby build
12:09:10 PM:
12:09:10 PM: Error location
12:09:10 PM: In Build command from Netlify app:
12:09:10 PM: gatsby build
12:09:10 PM:
12:09:10 PM: Resolved config
12:09:10 PM: build:
12:09:10 PM: command: gatsby build
12:09:10 PM: commandOrigin: ui
12:09:10 PM: publish: /opt/build/repo/public
12:09:11 PM: Caching artifacts
12:09:11 PM: Started saving build plugins
12:09:11 PM: Finished saving build plugins
12:09:11 PM: Started saving pip cache
12:09:11 PM: Finished saving pip cache
12:09:11 PM: Started saving emacs cask dependencies
12:09:11 PM: Finished saving emacs cask dependencies
12:09:11 PM: Started saving maven dependencies
12:09:11 PM: Finished saving maven dependencies
12:09:11 PM: Started saving boot dependencies
12:09:11 PM: Finished saving boot dependencies
12:09:11 PM: Started saving rust rustup cache
12:09:11 PM: Finished saving rust rustup cache
12:09:11 PM: Started saving go dependencies
12:09:11 PM: Finished saving go dependencies
12:09:13 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
12:09:13 PM: Creating deploy upload records
12:09:13 PM: Failing build: Failed to build site
12:09:13 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
12:09:13 PM: Finished processing build request in 28.232494224s
此问题通常与导致此输出的本地环境和 Netlify 环境之间的依赖关系不匹配有关。
尝试将您的 package.json
(如果是,在您的 Netlify 的仪表板中)命令更改为:
"build": "npm run build",
如果您在本地看到很多关于对等依赖项的警告,那么您将需要安装它们,因为 migration guide shows。
另一个可能对您有帮助的解决方法是使用 .nvmrc
文件修复您的 Node 版本。 运行:
node -v > .nvmrc
这将在项目的根目录中创建一个 .nvmrc
文件,其中包含 Node 版本 (node -v
)。 Netlify 在构建您的站点时将使用该文件来设置 Node 环境,如 docs 指出的那样。这在尝试调试某些问题的根源时非常有用。
此外,不要上传(尽快删除它并在 .gitignore
中忽略它)您的存储库中的 .cache
文件夹。你不想保留它,它会在你的回购中 pulling/pushing 东西时节省你的时间(如果其他人在你的项目中工作,可能会避免冲突)。