[英]Netlify 'build.command failed: base: /opt/build/repo/client' for deploying React app
I'm trying to deploy a React app to Netlify but in the deployment process I'm running into the following error:我正在尝试将 React 应用程序部署到 Netlify,但在部署过程中我遇到了以下错误:
...
9:11:17 AM: ────────────────────────────────────────────────────────────────
9:11:17 AM: "build.command" failed
9:11:17 AM: ────────────────────────────────────────────────────────────────
9:11:17 AM:
9:11:17 AM: Error message
9:11:17 AM: Command failed with exit code 1: npm run build
9:11:17 AM:
9:11:17 AM: Error location
9:11:17 AM: In Build command from Netlify app:
9:11:17 AM: npm run build
9:11:17 AM:
9:11:17 AM: Resolved config
9:11:17 AM: build:
9:11:17 AM: base: /opt/build/repo/client
9:11:17 AM: command: npm run build
9:11:17 AM: commandOrigin: ui
9:11:17 AM: publish: /opt/build/repo/client/build
9:11:17 AM: publishOrigin: ui
9:11:18 AM: Caching artifacts
9:11:18 AM: Started saving node modules
...
Keep in mind I am answering this question myself as I have found a solution and want to share it with anyone else who might run into the same issue.请记住,我自己在回答这个问题,因为我找到了解决方案,并希望与可能遇到相同问题的其他人分享。
I know this question is a bit old but I found a solution that solves it and thought I'd provide it in case someone else with a broken build stops by.我知道这个问题有点老了,但我找到了解决它的解决方案,并认为我会提供它,以防其他构建损坏的人停下来。
In order to build Next.js on Netlify you need to have the Netlify Next.js plugin installed.为了在 Netlify 上构建 Next.js,您需要安装 Netlify Next.js 插件。 You can do that by creating a
netlify.toml
file in the root of your project:您可以通过在项目的根目录中创建一个
netlify.toml
文件来做到这一点:
[[plugins]]
package = "@netlify/plugin-nextjs"
[build]
publish = ".next"
My scripts in the package.json
look like this:我在
package.json
中的脚本如下所示:
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
My Netlify settings look like this:我的 Netlify 设置如下所示:
The main thing to note is the following:主要需要注意的是:
.next
, which is the default directory when running next build
.next
,这是运行next build
时的默认目录next build
on Netlify so that the .next
directory gets generated.next build
,以便生成.next
目录。 I've done so by running npm run build
which is pointing to next build
.next build
的npm run build
来做到这一点。 Hopefully this helps anybody having this same issue!希望这可以帮助任何有同样问题的人!
Basically there is a problem with the npm run build
command that Netlify executes in the deployment process although, when running npm run build
locally it is successful.基本上,Netlify 在部署过程中执行的
npm run build
命令存在问题,尽管在本地运行npm run build
时它是成功的。
Therefore just removing the build step from the Netlify Continuous Deployment tab fixed the problem through bypassing the Netlify build process and just relying on the locally generated /build
folder as the Publish directory in the Netlify build settings.因此,只需从 Netlify 持续部署选项卡中删除构建步骤即可通过绕过 Netlify 构建过程并仅依赖本地生成的
/build
文件夹作为 Netlify 构建设置中的发布目录来解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.