将 Gatsby 站点部署到 Netlify 失败,在本地工作正常 - StaticImage 有问题吗?

时间:2021-05-09 22:29:07

标签: deployment gatsby netlify

我不明白为什么我的 Gatsby 站点无法在 Netlify 上部署。 以下是 Netlify 部署日志:

12:11:29 AM: Build ready to start
12:11:31 AM: build-image version: d03efc9bc7b65d83035572f6dba444f85407dd60
12:11:31 AM: build-image tag: v3.7.5
12:11:31 AM: buildbot version: 6dd06f64b3b0b51f07678bbd16c7e5a748905aed
12:11:31 AM: Building without cache
12:11:31 AM: Starting to prepare the repo for build
12:11:32 AM: No cached dependencies found. Cloning fresh repo
12:11:32 AM: git clone https://github.com/Boomstam/FAGQ
12:11:33 AM: Preparing Git Reference refs/heads/master
12:11:33 AM: Parsing package.json dependencies
12:11:35 AM: Starting build script
12:11:35 AM: Installing dependencies
12:11:35 AM: Python version set to 2.7
12:11:36 AM: v12.18.0 is already installed.
12:11:36 AM: Now using node v12.18.0 (npm v6.14.4)
12:11:37 AM: Started restoring cached build plugins
12:11:37 AM: Finished restoring cached build plugins
12:11:37 AM: Attempting ruby version 2.7.1, read from environment
12:11:38 AM: Using ruby version 2.7.1
12:11:38 AM: Using PHP version 5.6
12:11:38 AM: Started restoring cached node modules
12:11:38 AM: Finished restoring cached node modules
12:11:38 AM: Installing NPM modules using NPM version 6.14.4
12:12:22 AM: npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
12:12:22 AM: > sharp@0.28.1 install /opt/build/repo/node_modules/sharp
12:12:22 AM: > (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
12:12:24 AM: sharp: Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.10.6/libvips-8.10.6-linux-x64.tar.br
12:12:26 AM: > core-js@3.11.2 postinstall /opt/build/repo/node_modules/core-js
12:12:26 AM: > node -e "try{require('./postinstall')}catch(e){}"
12:12:26 AM: > core-js-pure@3.11.2 postinstall /opt/build/repo/node_modules/core-js-pure
12:12:26 AM: > node -e "try{require('./postinstall')}catch(e){}"
12:12:27 AM: > gatsby-telemetry@2.4.1 postinstall /opt/build/repo/node_modules/gatsby-telemetry
12:12:27 AM: > node src/postinstall.js || true
12:12:27 AM: > mozjpeg@7.0.0 postinstall /opt/build/repo/node_modules/mozjpeg
12:12:27 AM: > node lib/install.js
12:12:28 AM:   ✔ mozjpeg pre-build test passed successfully
12:12:28 AM: > pngquant-bin@6.0.0 postinstall /opt/build/repo/node_modules/pngquant-bin
12:12:28 AM: > node lib/install.js
12:12:28 AM:   ✔ pngquant pre-build test passed successfully
12:12:28 AM: > gatsby-cli@3.4.1 postinstall /opt/build/repo/node_modules/gatsby/node_modules/gatsby-cli
12:12:28 AM: > node scripts/postinstall.js
12:12:28 AM: > gatsby@3.4.1 postinstall /opt/build/repo/node_modules/gatsby
12:12:28 AM: > node scripts/postinstall.js
12:12:31 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/webpack-dev-server/node_modules/fsevents):
12:12:31 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
12:12:31 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
12:12:31 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
12:12:31 AM: added 2285 packages from 1062 contributors and audited 2288 packages in 51.769s
12:12:33 AM: 213 packages are looking for funding
12:12:33 AM:   run `npm fund` for details
12:12:33 AM: found 1 high severity vulnerability
12:12:33 AM:   run `npm audit fix` to fix them, or `npm audit` for details
12:12:33 AM: NPM modules installed
12:12:33 AM: Started restoring cached go cache
12:12:33 AM: Finished restoring cached go cache
12:12:34 AM: go version go1.14.4 linux/amd64
12:12:34 AM: go version go1.14.4 linux/amd64
12:12:34 AM: Installing missing commands
12:12:34 AM: Verify run directory
12:12:35 AM: ​
12:12:35 AM: ────────────────────────────────────────────────────────────────
12:12:35 AM:   Netlify Build                                                 
12:12:35 AM: ────────────────────────────────────────────────────────────────
12:12:35 AM: ​
12:12:35 AM: ❯ Version
12:12:35 AM:   @netlify/build 11.10.0
12:12:35 AM: ​
12:12:35 AM: ❯ Flags
12:12:35 AM:   deployId: 60985e1180c8566fcaaa04c1
12:12:35 AM: ​
12:12:35 AM: ❯ Current directory
12:12:35 AM:   /opt/build/repo
12:12:35 AM: ​
12:12:35 AM: ❯ Config file
12:12:35 AM:   No config file was defined: using default values.
12:12:35 AM: ​
12:12:35 AM: ❯ Context
12:12:35 AM:   production
12:12:35 AM: ​
12:12:35 AM: ────────────────────────────────────────────────────────────────
12:12:35 AM:   1. Build command from Netlify app                             
12:12:35 AM: ────────────────────────────────────────────────────────────────
12:12:35 AM: ​
12:12:35 AM: $ gatsby build
12:12:39 AM: success open and validate gatsby-configs - 0.013s
12:12:39 AM: success load plugins - 0.325s
12:12:39 AM: success onPreInit - 0.029s
12:12:39 AM: success initialize cache - 0.006s
12:12:39 AM: success copy gatsby files - 0.060s
12:12:39 AM: success onPreBootstrap - 0.016s
12:12:39 AM: success createSchemaCustomization - 0.001s
12:12:39 AM: success Checking for changed pages - 0.000s
12:12:39 AM: success source and transform nodes - 0.117s
12:12:40 AM: success building schema - 0.397s
12:12:40 AM: success createPages - 0.000s
12:12:40 AM: success createPagesStatefully - 0.057s
12:12:40 AM: info Total nodes: 37, SitePage nodes: 2 (use --verbose for breakdown)
12:12:40 AM: success Checking for changed pages - 0.000s
12:12:40 AM: success update schema - 0.076s
12:12:40 AM: success onPreExtractQueries - 0.002s
12:12:44 AM: success extract queries from components - 4.150s
12:13:08 AM: ​
12:13:08 AM: ────────────────────────────────────────────────────────────────
12:13:08 AM:   "build.command" failed                                        
12:13:08 AM: ────────────────────────────────────────────────────────────────
12:13:08 AM: ​
12:13:08 AM:   Error message
12:13:08 AM:   Command was killed with SIGKILL (Forced termination): gatsby build
12:13:08 AM: ​
12:13:08 AM:   Error location
12:13:08 AM:   In Build command from Netlify app:
12:13:08 AM:   gatsby build
12:13:08 AM: ​
12:13:08 AM:   Resolved config
12:13:08 AM:   build:
12:13:08 AM:     command: gatsby build
12:13:08 AM:     commandOrigin: ui
12:13:08 AM:     publish: /opt/build/repo/public
12:13:09 AM: Caching artifacts
12:13:09 AM: Started saving node modules
12:13:09 AM: Finished saving node modules
12:13:09 AM: Started saving build plugins
12:13:09 AM: Finished saving build plugins
12:13:09 AM: Started saving pip cache
12:13:09 AM: Finished saving pip cache
12:13:09 AM: Started saving emacs cask dependencies
12:13:09 AM: Finished saving emacs cask dependencies
12:13:09 AM: Started saving maven dependencies
12:13:09 AM: Finished saving maven dependencies
12:13:09 AM: Started saving boot dependencies
12:13:09 AM: Finished saving boot dependencies
12:13:09 AM: Started saving rust rustup cache
12:13:09 AM: Finished saving rust rustup cache
12:13:09 AM: Started saving go dependencies
12:13:09 AM: Finished saving go dependencies
12:13:12 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
12:13:12 AM: Creating deploy upload records
12:13:12 AM: Failing build: Failed to build site
12:13:12 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2
12:13:12 AM: Finished processing build request in 1m40.558266762s

我在尝试部署一个在本地运行良好的站点时遇到了这个问题。我无法确定问题所在,所以我开始进行故障排除。

我基于 gatsby hello-world 项目启动了一个新项目,该项目部署良好。然后我添加了样式组件,它们也能正常工作。

此后,deploy 问题出现;当我在主页(该项目中唯一的活动页面)上添加 StaticImage 以及 gatsby-plugins 和 gatsby-filesystem 时。在此之后,部署失败。

不幸的是,我发现实际上有几十个论坛帖子指向了与“Command was Killed with SIGKILL”错误相关的不同问题和解决方案;即便如此,到目前为止,他们都没有解决我的问题。

如果有人能就我的具体情况提供见解,我将不胜感激。

我在github上的代码: https://github.com/Boomstam/FAGQ

package.json

{
  "name": "gatsby-starter-hello-world",
  "private": true,
  "description": "A simplified bare-bones starter for Gatsby",
  "version": "0.1.0",
  "license": "0BSD",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "clean": "gatsby clean",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
  },
  "dependencies": {
    "gatsby": "^3.4.1",
    "gatsby-plugin-image": "^1.4.1",
    "gatsby-plugin-sharp": "^3.4.2",
    "gatsby-source-filesystem": "^3.4.0",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "styled-components": "^5.3.0"
  },
  "devDependencies": {
    "prettier": "2.2.1"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/gatsbyjs/gatsby-starter-hello-world"
  },
  "bugs": {
    "url": "https://github.com/gatsbyjs/gatsby/issues"
  }
}

gatsby-config.js

/**
 * Configure your Gatsby site with this file.
 *
 * See: https://www.gatsbyjs.com/docs/gatsby-config/
 */

module.exports = {
  /* Your site config here */
  plugins: [
    "gatsby-plugin-image",
    "gatsby-plugin-sharp",
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
  ],
}

1 个答案:

答案 0 :(得分:0)

我没有发现您的存储库中有任何问题,所以对我来说,您的本地环境和 Netlify 的部署环境之间存在版本不匹配。

尝试通过以下方式强制 Node 版本:

node -v > .nvmrc

这将使用当前 Node 版本在项目的根目录中生成一个 .nvmrc 文件。类似于:

v14.16.1

Netlify 在部署时会根据 their documentation 将该文件作为 Node 版本的基本配置。

相关问题