简体   繁体   English

Netlify 'build.command failed: base: /opt/build/repo/client' 用于部署 React 应用程序

[英]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:主要需要注意的是:

  • You must use the Netlify Next.js plugin which needs to be added to your project dependencies您必须使用需要添加到项目依赖项中的 Netlify Next.js 插件
  • Publish directory must be specified on Netlify to .next , which is the default directory when running next build发布目录必须在 Netlify 上指定为.next ,这是运行next build时的默认目录
  • You must run next build on Netlify so that the .next directory gets generated.您必须在 Netlify 上运行next build ,以便生成.next目录。 I've done so by running npm run build which is pointing to next build .我通过运行指向next buildnpm 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 构建设置中的发布目录来解决问题。

Here's a screenshot for reference:这是一个截图供参考: 在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 gatsby 网站的 Netlify “build.command”失败 - Netlify “build.command” failed for gatsby website Netlify/Craco 无法加载要扩展的配置“react-app”。 引用自:/opt/build/repo/package.json - Netlify/Craco Failed to load config "react-app" to extend from. Referenced from: /opt/build/repo/package.json 将应用程序部署到 Netlify:找不到模块:错误:无法解析 '/opt/build/repo/src' 中的 './pages/HomePage' - React app deployment to Netlify : Module not found: Error: Can't resolve './pages/HomePage' in '/opt/build/repo/src' Netlify 无法构建 React 应用程序 - 命令失败,退出代码为 1 - Netlify fails build for React app - Command failed with exit code 1 Netlify 构建因 React 应用程序中的 npm 错误而失败 - Netlify build failed for npm error in react app 在 .netlify 上部署我的 React 项目时显示错误:无法在 '/opt/build/repo/src/components/header' 中解析 '../../assets/CV.pdf' - while deploying my react project on netlify showing error: Can't resolve '../../assets/CV.pdf' in '/opt/build/repo/src/components/header' 部署React应用到Netlify时缺少构建脚本错误 - Missing Build scripts error in Deploying react app to netlify Gatsby 在 Netlify 上构建失败 - Gatsby Failed Build on Netlify 在netlify上部署构建时出错(错误:1) - Error deploying build on netlify (err: 1) Gatsby Netlify 构建错误:无法解析“/opt/build/repo/src/templates”中的“../components/GridTemplate/GridTemplate.js” - Gatsby Netlify build error: Can't resolve '../components/GridTemplate/GridTemplate.js' in '/opt/build/repo/src/templates'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM