无法部署React Project。错误是命令失败,退出代码为1

时间:2020-08-08 10:35:08

标签: reactjs

我写了我的React项目,可以在localhost上运行,也可以在计算机上使用yarn build命令进行构建。

我将项目推送到github(Repo)。当我想将项目部署到Vercel或Netlify时,出现了Cannot find file '../../components/collection-item/Collection-item' in './src/pages/collection'.错误,但是路径或其他东西都没有问题,正如我所说的,我可以运行并构建自己的计算机。我找不到解决方案。我更改了文件名和路径,仍然保持不变。

这是Netlify日志:

1:24:32 PM: build-image version: b0258b965567defc4a2d7e2f2dec2e00c8f73ad6
1:24:32 PM: build-image tag: v3.4.1
1:24:32 PM: buildbot version: bca3bbf1ce7c7ca2e2192b1683becc1d98c88c5b
1:24:32 PM: Fetching cached dependencies
1:24:32 PM: Failed to fetch cache, continuing with build
1:24:32 PM: Starting to prepare the repo for build
1:24:32 PM: No cached dependencies found. Cloning fresh repo
1:24:32 PM: git clone https://github.com/OrhanOzkercin/ReactShop
1:24:33 PM: Preparing Git Reference refs/heads/Build
1:24:34 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'build' versus 'build/' in the Netlify UI
1:24:34 PM: Starting build script
1:24:34 PM: Installing dependencies
1:24:34 PM: Python version set to 2.7
1:24:35 PM: v12.18.0 is already installed.
1:24:35 PM: Now using node v12.18.0 (npm v6.14.4)
1:24:35 PM: Started restoring cached build plugins
1:24:35 PM: Finished restoring cached build plugins
1:24:36 PM: Attempting ruby version 2.7.1, read from environment
1:24:37 PM: Using ruby version 2.7.1
1:24:37 PM: Using PHP version 5.6
1:24:37 PM: 5.2 is already installed.
1:24:37 PM: Using Swift version 5.2
1:24:37 PM: Started restoring cached node modules
1:24:37 PM: Finished restoring cached node modules
1:24:37 PM: Started restoring cached yarn cache
1:24:37 PM: Finished restoring cached yarn cache
1:24:37 PM: Installing yarn at version 1.22.4
1:24:37 PM: Installing Yarn!
1:24:37 PM: > Downloading tarball...
1:24:37 PM: [1/2]: https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz --> /tmp/yarn.tar.gz.fZhfENjJTT
1:24:37 PM:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
1:24:37 PM:                                  Dload  Upload   Total   Spent    Left  Speed
1:24:37 PM:   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
1:24:37 PM: 100    80  100    80    0     0    249      0 --:--:-- --:--:-- --:--:--   249
1:24:38 PM:   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
1:24:38 PM: 100    93  100    93    0     0    139      0 --:--:-- --:--:-- --:--:--   332
1:24:38 PM: 100   630  100   630    0     0    612      0  0:00:01  0:00:01 --:--:--   612
1:24:39 PM:  22 1215k   22  270k    0     0   194k      0  0:00:06  0:00:01  0:00:05  194k
1:24:39 PM: 100 1215k  100 1215k    0     0   840k      0  0:00:01  0:00:01 --:--:-- 17.0M
1:24:39 PM: [2/2]: https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz.asc --> /tmp/yarn.tar.gz.fZhfENjJTT.asc
1:24:39 PM: 100    84  100    84    0     0   2358      0 --:--:-- --:--:-- --:--:--  2358
1:24:39 PM: 100    97  100    97    0     0   1433      0 --:--:-- --:--:-- --:--:--  1433
1:24:39 PM: 100   634  100   634    0     0   2905      0 --:--:-- --:--:-- --:--:--  2905
1:24:39 PM: 100  1028  100  1028    0     0   3986      0 --:--:-- --:--:-- --:--:--  3986
1:24:39 PM: > Verifying integrity...
1:24:39 PM: gpg: Signature made Mon 09 Mar 2020 03:52:13 PM UTC using RSA key ID 69475BAA
1:24:39 PM: gpg: Good signature from "Yarn Packaging <yarn@dan.cx>"
1:24:39 PM: gpg: WARNING: This key is not certified with a trusted signature!
1:24:39 PM: gpg:          There is no indication that the signature belongs to the owner.
1:24:39 PM: Primary key fingerprint: 72EC F46A 56B4 AD39 C907  BBB7 1646 B01B 86E5 0310
1:24:39 PM:      Subkey fingerprint: 6D98 490C 6F1A CDDD 448E  4595 4F77 6793 6947 5BAA
1:24:39 PM: > GPG signature looks good
1:24:39 PM: > Extracting to ~/.yarn...
1:24:39 PM: > Adding to $PATH...
1:24:39 PM: > Successfully installed Yarn 1.22.4! Please open another terminal where the `yarn` command will now be available.
1:24:40 PM: Installing NPM modules using Yarn version 1.22.4
1:24:40 PM: yarn install v1.22.4
1:24:40 PM: [1/4] Resolving packages...
1:24:41 PM: [2/4] Fetching packages...
1:25:03 PM: info fsevents@2.1.2: The platform "linux" is incompatible with this module.
1:25:03 PM: info "fsevents@2.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
1:25:03 PM: info fsevents@1.2.13: The platform "linux" is incompatible with this module.
1:25:03 PM: info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
1:25:03 PM: info fsevents@2.1.3: The platform "linux" is incompatible with this module.
1:25:03 PM: info "fsevents@2.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
1:25:03 PM: [3/4] Linking dependencies...
1:25:03 PM: warning " > @testing-library/user-event@7.2.1" has unmet peer dependency "@testing-library/dom@>=5".
1:25:03 PM: warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
1:25:03 PM: warning " > styled-components@5.1.1" has unmet peer dependency "react-is@>= 16.8.0".
1:25:15 PM: [4/4] Building fresh packages...
1:25:17 PM: Done in 36.81s.
1:25:17 PM: NPM modules installed using Yarn
1:25:17 PM: Started restoring cached go cache
1:25:17 PM: Finished restoring cached go cache
1:25:17 PM: go version go1.14.4 linux/amd64
1:25:17 PM: go version go1.14.4 linux/amd64
1:25:17 PM: Installing missing commands
1:25:17 PM: Verify run directory
1:25:18 PM: ​
1:25:18 PM: ┌─────────────────────────────┐
1:25:18 PM: │        Netlify Build        │
1:25:18 PM: └─────────────────────────────┘
1:25:19 PM: ​
1:25:19 PM: ❯ Version
1:25:19 PM:   @netlify/build 3.1.10
1:25:19 PM: ​
1:25:19 PM: ❯ Flags
1:25:19 PM:   deployId: 5f2e7d5a88b3fd0007415022
1:25:19 PM:   mode: buildbot
1:25:19 PM:   timersFile: /tmp/substage_times.txt
1:25:19 PM: ​
1:25:19 PM: ❯ Current directory
1:25:19 PM:   /opt/build/repo
1:25:19 PM: ​
1:25:19 PM: ❯ Config file
1:25:19 PM:   No config file was defined: using default values.
1:25:19 PM: ​
1:25:19 PM: ❯ Context
1:25:19 PM:   production
1:25:19 PM: ​
1:25:19 PM: ┌───────────────────────────────────┐
1:25:19 PM: │ 1. Build command from Netlify app │
1:25:19 PM: └───────────────────────────────────┘
1:25:19 PM: ​
1:25:19 PM: $ yarn build
1:25:19 PM: yarn run v1.22.4
1:25:19 PM: $ react-scripts build
1:25:20 PM: Creating an optimized production build...
1:25:27 PM: Failed to compile.
1:25:27 PM: 
1:25:27 PM: ./src/pages/collection/Collectionpage.jsx
1:25:27 PM: Cannot find file '../../components/collection-item/Collection-item' in './src/pages/collection'.
1:25:28 PM: error Command failed with exit code 1.
1:25:28 PM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
1:25:28 PM:   
1:25:28 PM:   If the build failed with a warning about "process.env.CI = true", this is due to "create-react-app" treating warnings as errors when in CI. In order to fix this problem, please either:
1:25:28 PM:     - Fix the issues highlighted by the warnings above.
1:25:28 PM:     - Or modify the "scripts.build" command in your "package.json" from "react-scripts build" to "CI= react-scripts build"
1:25:28 PM:   More information can be found at https://docs.netlify.com/configure-builds/troubleshooting-tips/#build-fails-on-warning-message
1:25:28 PM: ​
1:25:28 PM: ┌─────────────────────────────┐
1:25:28 PM: │   "build.command" failed    │
1:25:28 PM: └─────────────────────────────┘
1:25:28 PM: ​
1:25:28 PM:   Error message
1:25:28 PM:   Command failed with exit code 1: yarn build
1:25:28 PM: ​
1:25:28 PM:   Error location
1:25:28 PM:   In Build command from Netlify app:
1:25:28 PM:   yarn build
1:25:28 PM: ​
1:25:28 PM:   Resolved config
1:25:28 PM:   build:
1:25:28 PM:     command: yarn build
1:25:28 PM:     commandOrigin: ui
1:25:28 PM:     publish: /opt/build/repo/build
1:25:28 PM: Caching artifacts
1:25:28 PM: Started saving node modules
1:25:28 PM: Finished saving node modules
1:25:28 PM: Started saving build plugins
1:25:28 PM: Finished saving build plugins
1:25:28 PM: Started saving yarn cache
1:25:28 PM: Finished saving yarn cache
1:25:28 PM: Started saving pip cache
1:25:28 PM: Finished saving pip cache
1:25:28 PM: Started saving emacs cask dependencies
1:25:28 PM: Finished saving emacs cask dependencies
1:25:28 PM: Started saving maven dependencies
1:25:28 PM: Finished saving maven dependencies
1:25:28 PM: Started saving boot dependencies
1:25:28 PM: Finished saving boot dependencies
1:25:28 PM: Started saving go dependencies
1:25:28 PM: Finished saving go dependencies
1:25:30 PM: Error running command: Build script returned non-zero exit code: 1
1:25:30 PM: Failing build: Failed to build site
1:25:30 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1
1:25:30 PM: Finished processing build request in 58.952206659s```


 

3 个答案:

答案 0 :(得分:0)

进入package.json和脚本,用以下内容替换build:

"build": "CI= react-scripts build",

答案 1 :(得分:0)

回答有同样问题的人。

就我而言,我将某些文件名更改为大写版本。问题是Git无法解决此更改,这就是为什么我的文件结构在Github上错误的原因。因此,解决方案是使用git更改此配置。

git config core.ignorecase false此命令使git知道大写。

这是Stacoverflow上的另一个问题:I change the capitalization of a directory and Git doesn't seem to pick up on it

答案 2 :(得分:0)

您可以在 package.json 和脚本中,将 build 替换为:

"build": "CI= npm run build"

您可以在他们的社区中阅读有关此错误原因的更多信息:

https://answers.netlify.com/t/netlify-not-building-command-failed-with-exit-code-1-npm-run-build/16999/2