8

I wrote my React project and can run on localhost and also I can build with yarn build command on my computer.

I pushed my project to github ( Repo ). When I want to deploy to my project to Vercel or Netlify I'm getting error which is Cannot find file '../../components/collection-item/Collection-item' in './src/pages/collection'. but there is no problem with path or something as I said I can run and build it my own computer. I couldn't find a solution. I changed file name and path still same.

Here is Netlify Logs:

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```


 
Orhan Özkerçin
  • 342
  • 1
  • 4
  • 14
  • Did you try to change `import CollectionItem from ../../components/collection-item/Collection-item` to `import CollectionItem from ../../components/collection-item/collection-item` locally? – onuriltan Aug 08 '20 at 12:41
  • Sure, but this is not the path of file that's why it throw an error. As I said path is okey and it's working on my computer. Problem occuring while uploading. Even in my computer I can build it succesfully. – Orhan Özkerçin Aug 08 '20 at 13:00
  • 1
    I cloned your project and it was giving the same error locally, after I change the letter of your component imports from capitalized to non-capitalized it worked locally, not sure about the deployment though. – onuriltan Aug 08 '20 at 13:03
  • 2
    Weird thing after you told me I cloned project from github and I saw that file names are different. The think is if I changed file names to capitalized version when I want to push git it says repo is up-to-date. But I'll digg into. I think it's about pushing github. I didn't realise before. Thank you very much! – Orhan Özkerçin Aug 08 '20 at 13:12
  • @OrhanÖzkerçin I have given solution for your problem, kindly look at that once, last day I had the same problem and solved it using this solution. – Himanshu Bhardwaj Aug 08 '20 at 13:16
  • @HimanshuBhardwaj Thank you for your intererst, I tried to your solution but problem is about when I changed file name can not send it to github changed version. I thnik when I fix this It will be fine. [Here is commit that I tried your solution](https://github.com/OrhanOzkercin/ReactShop/commit/82e47b3b0ed843cfd2eb35e8469d0bacc13c8aec) – Orhan Özkerçin Aug 08 '20 at 13:24

6 Answers6

16

Go in package.json and in scripts, replace build with this:

"build": "CI= react-scripts build",
  • 1
    This works. It seems that the build fails when there are warnings. CI is responsible for that. More can be found [here](https://community.netlify.com/t/build-error-command-failed-with-exit-code-1-yarn-build/17666). Search for "treating warnings as errors" – Gilbert Jan 09 '21 at 10:06
3

Answer for people who has same problem.

In my case I changed some of my files name to capitalize version. The problem was Git didn't resolve this change that's why my file structure was wrong on Github. So Solution is changind this config with git.

git config core.ignorecase false this command makes git to be aware of capitalization.

Here is another question on Stacoverflow: I change the capitalization of a directory and Git doesn't seem to pick up on it

Orhan Özkerçin
  • 342
  • 1
  • 4
  • 14
  • My build was failing trying to push to firebase, and I hadn't realized it but the file capitalizations were different between what was getting pushed to git and what I actually had locally. – Riunge Maina Dec 29 '21 at 06:58
1
 CI= npm run build 
  • Site setting -> Build & deploy
  • change build command CI= npm run
  • build Redeploy your website
Spandan Joshi
  • 809
  • 10
  • 11
0

You can go in package.json and in scripts, replace build with:

"build": "CI= npm run build"

You can read more about the causes of this error in their community:

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

Blessing
  • 2,450
  • 15
  • 22
0

In netlify,

Under Deploy Setting of the site:
Change Build Command to CI= npm run build

It should be Build command: CI= npm run build

ShivamH
  • 11
  • 3
0

if you are deploying React app on netlify use the following approach

In Basic build setting:-

  1. Base directory= (empty if inside the repo which you are making live you have direct access to the components)else (the root-directory name)
  2. Build Command = ( CI= npm run build )
  3. Publish Directory = (build) if no root directory or else (root-directory/build)

note- make sure to check the package.json file and inside the "script" you should have build script i.e "build": "react-scripts build",