【问题标题】:Gatsby build failing when deploying to Netlify部署到 Netlify 时 Gatsby 构建失败
【发布时间】:2021-03-04 07:50:09
【问题描述】:

我目前正在尝试在暂存环境中查看我的网站,因此我正在从暂存分支推送。不是大师。

它完全在本地构建。推送到 Netlify 时,它会失败。

我得到的错误如下:

3:31:59 PM: ────────────────────────────────────────────────────────────────
3:31:59 PM:   1. Build command from Netlify app                             
3:31:59 PM: ────────────────────────────────────────────────────────────────
3:31:59 PM: ​
3:31:59 PM: $ gatsby build
3:31:59 PM: bash: gatsby: command not found
3:31:59 PM: ​
3:31:59 PM: ────────────────────────────────────────────────────────────────
3:31:59 PM:   "build.command" failed                                        
3:31:59 PM: ────────────────────────────────────────────────────────────────
3:31:59 PM: ​
3:31:59 PM:   Error message
3:31:59 PM:   Command failed with exit code 127: gatsby build
3:31:59 PM: ​
3:31:59 PM:   Error location
3:31:59 PM:   In Build command from Netlify app:
3:31:59 PM:   gatsby build
3:31:59 PM: ​
3:31:59 PM:   Resolved config
3:31:59 PM:   build:
3:31:59 PM:     command: gatsby build
3:31:59 PM:     commandOrigin: ui
3:31:59 PM:     publish: /opt/build/repo/dist
3:31:59 PM: Caching artifacts
3:31:59 PM: Started saving node modules
3:31:59 PM: Finished saving node modules
3:31:59 PM: Started saving build plugins
3:31:59 PM: Finished saving build plugins
3:31:59 PM: Started saving yarn cache
3:31:59 PM: Finished saving yarn cache
3:31:59 PM: Started saving pip cache
3:31:59 PM: Finished saving pip cache
3:31:59 PM: Started saving emacs cask dependencies
3:31:59 PM: Finished saving emacs cask dependencies
3:31:59 PM: Started saving maven dependencies
3:31:59 PM: Finished saving maven dependencies
3:31:59 PM: Started saving boot dependencies
3:31:59 PM: Finished saving boot dependencies
3:31:59 PM: Started saving go dependencies
3:32:01 PM: Finished saving go dependencies
3:32:04 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:32:04 PM: Failing build: Failed to build site
3:32:04 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
3:32:04 PM: Finished processing build request in 1m17.166375156s

【问题讨论】:

    标签: reactjs gatsby netlify


    【解决方案1】:

    您遇到的错误是 gatsby CLI 不可用。

    bash: gatsby: 找不到命令

    1. 检查 package.json 的依赖项中是否包含 gatsby。请注意,它不能在您的 devDependencies 中。
    2. 在显示的错误消息上方,您应该看到 Netlify 选择了 Yarn 或 NPM 并根据需要安装依赖项。如果没有,您可能忘记在您的 repo 中包含 package-lock.json 或 yarn.lock(例如,它可能在 .gitignore 中)。
    3. 为避免将来出现此类问题,请将“构建”脚本添加到您的 package.json 并切换 Netlify 上的构建命令以使用它(例如 yarn buildnpm run build)。这将确保您使用的是 node_modules 中包含的可执行文件,而不是全局可用的工具。

    【讨论】:

      猜你喜欢
      • 2021-09-10
      • 2021-03-08
      • 2019-09-29
      • 1970-01-01
      • 2021-10-27
      • 2020-05-09
      • 1970-01-01
      • 2020-07-04
      相关资源
      最近更新 更多