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



本地(使用"gatsby-development"(运行良好,但当我使用"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

我已经完成了所有的标准操作,比如重新安装node和npm(因为我认为这可能是一个问题(,但几周后,我完全不知道问题是什么。同样,网上没有大量的文档,甚至不知道从哪里开始解决这个问题。

gatsby-node.js中,您将有一个类似于下面的导出。modifyWebpackConfig在《盖茨比》第二版中被删除并替换为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],
})
}
}

请参阅此处的文档。

最新更新