错误 运行 命令:生成脚本返回非零退出代码:1

Error running command: Build script returned non-zero exit code: 1

在本地(使用 'gatsby develop')它运行良好 - 但是当我使用 'gatsby build' 部署到 Netlify 时,我收到此错误:

########################################################################

6:15:57 AM:   ⚠ mozjpeg pre-build test failed
6:15:57 AM:   ℹ compiling from source
6:16:33 AM:   ✔ mozjpeg built successfully
6:16:33 AM: > pngquant-bin@5.0.0 postinstall /opt/build/repo/node_modules/pngquant-bin
6:16:33 AM: > node lib/install.js
6:16:34 AM:   ✔ pngquant pre-build test passed successfully
6:16:42 AM: npm
6:16:42 AM:  WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
6:16:42 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
6:16:42 AM: added 1945 packages from 1150 contributors and audited 27946 packages in 94.548s
6:16:42 AM: found 5 moderate severity vulnerabilities
6:16:42 AM:   run `npm audit fix` to fix them, or `npm audit` for details
6:16:42 AM: NPM modules installed
6:16:42 AM: Started restoring cached go cache
6:16:42 AM: Finished restoring cached go cache
6:16:42 AM: unset GOOS;
6:16:42 AM: unset GOARCH;
6:16:42 AM: export GOROOT='/opt/buildhome/.gimme/versions/go1.10.linux.amd64';
6:16:42 AM: export PATH="/opt/buildhome/.gimme/versions/go1.10.linux.amd64/bin:${PATH}";
6:16:42 AM: go version >&2;
6:16:42 AM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.10.linux.amd64.env';
6:16:42 AM: go version go1.10 linux/amd64
6:16:42 AM: Installing missing commands
6:16:42 AM: Verify run directory
6:16:43 AM: Executing user command: gatsby build
6:16:45 AM: success open and validate gatsby-config — 0.017 s
6:16:45 AM: Your plugins must export known APIs from their gatsby-node.js.
6:16:45 AM: The following exports aren't APIs. Perhaps you made a typo or your plugin is outdated?
6:16:45 AM: See https://www.gatsbyjs.org/docs/node-apis/ for the list of Gatsby Node APIs
6:16:45 AM: - Your site's gatsby-node.js is exporting "modifyWebpackConfig" which was removed in Gatsby v2. Refer to the migration guide for more info on upgrading to "onCreateWebpackConfig":
6:16:45 AM:  https://gatsby.app/update-webpack-config
6:16:45 AM: Caching artifacts
6:16:45 AM: Started saving node modules
6:16:45 AM: Finished saving node modules
6:16:45 AM: Started saving pip cache
6:16:45 AM: Finished saving pip cache
6:16:45 AM: Started saving emacs cask dependencies
6:16:45 AM: Finished saving emacs cask dependencies
6:16:45 AM: Started saving maven dependencies
6:16:45 AM: Finished saving maven dependencies
6:16:45 AM: Started saving boot dependencies
6:16:45 AM: Finished saving boot dependencies
6:16:45 AM: Started saving go dependencies
6:16:45 AM: Finished saving go dependencies
6:16:46 AM: Cached node version v8.12.0
6:16:46 AM: Error running command: Build script returned non-zero exit code: 1
6:16:46 AM: Failing build: Failed to build site
6:16:46 AM: failed during stage 'building site': Build script returned non-zero exit code: 1
6:16:46 AM: Finished processing build request in 1m47.357793899s

已经完成了所有标准操作,例如重新安装节点和 npm(我认为这可能是个问题)但是,几周后,我完全不知道问题是什么。同样,没有大量的在线文档如此难以确定从哪里开始解决这个问题。

在您的 gatsby-node.js 中,您将有一个类似于下面的导出。 modifyWebpackConfig 在 Gatsby 的第 2 版中被删除并替换为 onCreateWebpackConfig

exports.modifyWebpackConfig = ({ config, stage }) => {
  switch (stage) {
    case `build-javascript`:
    config.plugin(`Foo`, webpackFooPlugin, null)
    break
  }
  return config
};

现已更改为:

exports.onCreateWebpackConfig = ({ stage, actions }) => {
  switch (stage) {
    case `build-javascript`:
      actions.setWebpackConfig({
        plugins: [webpackFooPlugin],
      })
  }
}

See docs here.