为什么我的 React Netlify 部署失败?

问题描述 投票:0回答:2

我还需要添加什么到我的 netlify 仪表板才能成功部署?我的基本目录是“client/”,但在失败的构建过程中,我收到以下错误消息:

3:43:00 AM: Build ready to start
3:43:02 AM: build-image version: c5b01a919d3e16af69445c5de0cacb49efbb1a23 (focal)
3:43:02 AM: build-image tag: v4.4.0
3:43:02 AM: buildbot version: 9deea8f876b3228119111d3a654f519dd1866bfe
3:43:02 AM: Fetching cached dependencies
3:43:02 AM: Starting to download cache of 25.7MB
3:43:02 AM: Finished downloading cache in 263.782804ms
3:43:02 AM: Starting to extract cache
3:43:03 AM: Finished extracting cache in 322.289992ms
3:43:03 AM: Finished fetching cache in 592.560159ms
3:43:03 AM: Starting to prepare the repo for build
3:43:03 AM: Preparing Git Reference refs/heads/master
3:43:03 AM: Parsing package.json dependencies
3:43:04 AM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'client' versus '' in the Netlify UI
3:43:04 AM: Starting build script
3:43:04 AM: Installing dependencies
3:43:04 AM: Python version set to 2.7
3:43:05 AM: Downloading and installing node v16.13.0...
3:43:05 AM: Downloading https://nodejs.org/dist/v16.13.0/node-v16.13.0-linux-x64.tar.xz...
3:43:05 AM: Computing checksum with sha256sum
3:43:05 AM: Checksums matched!
3:43:08 AM: Now using node v16.13.0 (npm v8.1.0)
3:43:08 AM: Started restoring cached build plugins
3:43:08 AM: Finished restoring cached build plugins
3:43:08 AM: Attempting ruby version 2.7.2, read from environment
3:43:09 AM: Using ruby version 2.7.2
3:43:09 AM: Using PHP version 8.0
3:43:09 AM: Started restoring cached node modules
3:43:09 AM: Finished restoring cached node modules
3:43:10 AM: Installing NPM modules using NPM version 8.1.0
3:43:24 AM: npm WARN deprecated [email protected]: flatten is deprecated in favor of utility frameworks such as lodash.
3:43:24 AM: npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
3:43:24 AM: npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
3:43:25 AM: npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
3:43:25 AM: npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
3:43:28 AM: npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
3:43:28 AM: npm WARN deprecated [email protected]: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
3:43:28 AM: npm WARN deprecated [email protected]: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-babel.
3:43:35 AM: npm WARN deprecated [email protected]: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
3:43:36 AM: npm WARN deprecated @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
3:43:36 AM: npm WARN deprecated @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
3:43:37 AM: npm WARN deprecated @hapi/[email protected]: Moved to 'npm install @sideway/address'
3:43:38 AM: npm WARN deprecated @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
3:43:38 AM: npm WARN deprecated [email protected]: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
3:43:39 AM: npm WARN deprecated [email protected]: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
3:43:39 AM: npm WARN deprecated [email protected]: This SVGO version is no longer supported. Upgrade to v2.x.x.
3:43:39 AM: npm WARN deprecated @babel/[email protected]: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information.
3:43:40 AM: npm WARN deprecated @hapi/[email protected]: Switch to 'npm install joi'
3:43:46 AM: npm WARN deprecated [email protected]: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
3:43:46 AM: npm WARN deprecated [email protected]: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
3:43:48 AM: added 1923 packages, and audited 1924 packages in 38s
3:43:48 AM: 155 packages are looking for funding
3:43:48 AM:   run `npm fund` for details
3:43:48 AM: 58 vulnerabilities (16 moderate, 40 high, 2 critical)
3:43:48 AM: To address issues that do not require attention, run:
3:43:48 AM:   npm audit fix
3:43:48 AM: To address all issues (including breaking changes), run:
3:43:48 AM:   npm audit fix --force
3:43:48 AM: Run `npm audit` for details.
3:43:48 AM: NPM modules installed
3:43:49 AM: Started restoring cached go cache
3:43:49 AM: Finished restoring cached go cache
3:43:49 AM: go version go1.16.5 linux/amd64
3:43:49 AM: go version go1.16.5 linux/amd64
3:43:49 AM: Installing missing commands
3:43:49 AM: Verify run directory
3:43:50 AM: ​
3:43:50 AM: ────────────────────────────────────────────────────────────────
3:43:50 AM:   Netlify Build                                                 
3:43:50 AM: ────────────────────────────────────────────────────────────────
3:43:50 AM: ​
3:43:50 AM: ❯ Version
3:43:50 AM:   @netlify/build 18.20.1
3:43:50 AM: ​
3:43:50 AM: ❯ Flags
3:43:50 AM:   baseRelDir: true
3:43:50 AM:   buildId: 617e49046c02f5404dbc1a69
3:43:50 AM:   deployId: 617e49046c02f5404dbc1a6b
3:43:50 AM: ​
3:43:50 AM: ❯ Current directory
3:43:50 AM:   /opt/build/repo/client
3:43:50 AM: ​
3:43:50 AM: ❯ Config file
3:43:50 AM:   No config file was defined: using default values.
3:43:50 AM: ​
3:43:50 AM: ❯ Context
3:43:50 AM:   production
3:43:50 AM: ​
3:43:50 AM: ────────────────────────────────────────────────────────────────
3:43:50 AM:   1. Build command from Netlify app                             
3:43:50 AM: ────────────────────────────────────────────────────────────────
3:43:50 AM: ​
3:43:50 AM: $ npm run build
3:43:50 AM: > [email protected] build
3:43:50 AM: > react-scripts build
3:43:52 AM: Could not find a required file.
3:43:52 AM:   Name: index.html
3:43:52 AM:   Searched in: /opt/build/repo/client/public
3:43:52 AM: ​
3:43:52 AM: ────────────────────────────────────────────────────────────────
3:43:52 AM:   "build.command" failed                                        
3:43:52 AM: ────────────────────────────────────────────────────────────────
3:43:52 AM: ​
3:43:52 AM:   Error message
3:43:52 AM:   Command failed with exit code 1: npm run build
3:43:52 AM: ​
3:43:52 AM:   Error location
3:43:52 AM:   In Build command from Netlify app:
3:43:52 AM:   npm run build
3:43:52 AM: ​
3:43:52 AM:   Resolved config
3:43:52 AM:   build:
3:43:52 AM:     base: /opt/build/repo/client
3:43:52 AM:     command: npm run build
3:43:52 AM:     commandOrigin: ui
3:43:52 AM:     publish: /opt/build/repo/client
3:43:52 AM:     publishOrigin: default
3:43:52 AM: Caching artifacts
3:43:52 AM: Started saving node modules
3:43:52 AM: Finished saving node modules
3:43:52 AM: Started saving build plugins
3:43:52 AM: Finished saving build plugins
3:43:52 AM: Started saving pip cache
3:43:53 AM: Finished saving pip cache
3:43:53 AM: Started saving emacs cask dependencies
3:43:53 AM: Finished saving emacs cask dependencies
3:43:53 AM: Started saving maven dependencies
3:43:53 AM: Finished saving maven dependencies
3:43:53 AM: Started saving boot dependencies
3:43:53 AM: Finished saving boot dependencies
3:43:53 AM: Started saving rust rustup cache
3:43:53 AM: Finished saving rust rustup cache
3:43:53 AM: Started saving go dependencies
3:43:53 AM: Finished saving go dependencies
3:43:55 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:43:55 AM: Creating deploy upload records
3:43:55 AM: Failing build: Failed to build site
3:43:55 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2
3:43:55 AM: Finished processing build request in 53.456328243s

这就是我的上述部署设置:

当我删除“npm run build”命令,并将“client”路径保留为我的基本目录时,构建通过,并且部署了网站,但没有显示任何内容,并显示“找不到页面”错误。这就是构建日志的样子:

12:01:38 PM: Build ready to start
12:01:40 PM: build-image version: c5b01a919d3e16af69445c5de0cacb49efbb1a23 (focal)
12:01:40 PM: build-image tag: v4.4.0
12:01:40 PM: buildbot version: 9deea8f876b3228119111d3a654f519dd1866bfe
12:01:40 PM: Fetching cached dependencies
12:01:40 PM: Starting to download cache of 25.7MB
12:01:40 PM: Finished downloading cache in 441.765419ms
12:01:40 PM: Starting to extract cache
12:01:41 PM: Finished extracting cache in 443.667129ms
12:01:41 PM: Finished fetching cache in 897.128839ms
12:01:41 PM: Starting to prepare the repo for build
12:01:41 PM: Preparing Git Reference refs/heads/master
12:01:42 PM: Parsing package.json dependencies
12:01:42 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'client' versus '' in the Netlify UI
12:01:43 PM: No build steps found, continuing to publishing
12:01:43 PM: Starting to deploy site from 'client'
12:01:43 PM: Creating deploy tree 
12:01:43 PM: Creating deploy upload records
12:01:43 PM: 0 new files to upload
12:01:43 PM: 0 new functions to upload
12:01:43 PM: Starting post processing
12:01:43 PM: Post processing - HTML
12:01:43 PM: Post processing - header rules
12:01:43 PM: Post processing - redirect rules
12:01:43 PM: Post processing done
12:01:43 PM: Site is live ✨
12:01:46 PM: Finished processing build request in 6.034543908s

最后,我尝试将“build”文件夹推送到客户端目录下的github repo,并将基目录更改为“client/build”,再次构建通过,但域链接仍然损坏。这是日志:

12:18:12 PM: Build ready to start
12:18:14 PM: build-image version: c5b01a919d3e16af69445c5de0cacb49efbb1a23 (focal)
12:18:14 PM: build-image tag: v4.4.0
12:18:14 PM: buildbot version: 9deea8f876b3228119111d3a654f519dd1866bfe
12:18:14 PM: Fetching cached dependencies
12:18:14 PM: Starting to download cache of 25.7MB
12:18:15 PM: Finished downloading cache in 552.078967ms
12:18:15 PM: Starting to extract cache
12:18:15 PM: Finished extracting cache in 409.971688ms
12:18:15 PM: Finished fetching cache in 971.985738ms
12:18:15 PM: Starting to prepare the repo for build
12:18:15 PM: Preparing Git Reference refs/heads/master
12:18:16 PM: Parsing package.json dependencies
12:18:16 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'client/build' versus '' in the Netlify UI
12:18:17 PM: No build steps found, continuing to publishing
12:18:17 PM: Starting to deploy site from 'client/build'
12:18:17 PM: Creating deploy tree 
12:18:17 PM: Creating deploy upload records
12:18:17 PM: 0 new files to upload
12:18:17 PM: 0 new functions to upload
12:18:17 PM: Starting post processing
12:18:17 PM: Post processing - HTML
12:18:17 PM: Post processing - header rules
12:18:17 PM: Post processing - redirect rules
12:18:17 PM: Post processing done
12:18:17 PM: Site is live ✨
12:18:20 PM: Finished processing build request in 5.854033726s

我有什么遗漏的吗?这个过程实在是让人费解。我会留下我的仓库以防万一:https://github.com/darienmiller88/Task-Scheduler

reactjs netlify
2个回答
0
投票

尝试将“构建命令”从“npm run build”更改为“CI=npm run build”。

它可以避免部署时出现在您的站点上的任何警告。

更多信息在这里: https://levelup.gitconnected.com/how-to-deploy-a-react-app-with-netlify-set-up-continuous-deployment-via-github-53859dcdaf40


0
投票

解决方案:直接更改 Netlify 上的部署设置: 在 Netlify 中打开“站点详细信息” - 构建和部署 - 环境 - 环境变量 - 编辑变量并将键设置为 CI,值设置为 false。

© www.soinside.com 2019 - 2024. All rights reserved.