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

时间:2018-11-06 00:59:10

标签: reactjs deployment gatsby netlify

在本地(使用“ gatsby开发”)运行良好-但是当我使用“ 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(我认为这可能是个问题),但是,在几周后,我对问题的根源感到非常困惑。同样,在线上也没有大量的文档,甚至在开始着手解决此问题方面都相当棘手。

1 个答案:

答案 0 :(得分:0)

在您的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.