Build Failed during stage 'building site': Build script returned non-zero exit code: 2

I keep getting build errors despite following the docs and making sure my build scripts are correct

If i’m understanding, the build is failing due to not being able to find a page “Home”. This is the home pag e I’ve set up in my web app, and it works with react router in localhost. I double checked the file names for case and spelling and everything is perfect so I don’t get how that would be an issue.
*
*Build log

3:23:39 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
3:23:35 PM: Netlify Build
3:23:35 PM: ────────────────────────────────────────────────────────────────
3:23:35 PM: ​
3:23:35 PM: ❯ Version
3:23:35 PM: @netlify/build 29.15.0
3:23:35 PM: ​
3:23:35 PM: ❯ Flags
3:23:35 PM: baseRelDir: true
3:23:35 PM: buildId: 649f55c80103a855884991ac
3:23:35 PM: deployId: 649f55c80103a855884991ae
3:23:35 PM: ​
3:23:35 PM: ❯ Current directory
3:23:35 PM: /opt/build/repo
3:23:35 PM: ​
3:23:35 PM: ❯ Config file
3:23:35 PM: No config file was defined: using default values.
3:23:35 PM: ​
3:23:35 PM: ❯ Context
3:23:35 PM: production
3:23:35 PM: ​
3:23:35 PM: Build command from Netlify app
3:23:35 PM: ────────────────────────────────────────────────────────────────
3:23:35 PM: ​
3:23:35 PM: $ npm run build
3:23:36 PM: > mso-photo@0.1.0 build
3:23:36 PM: > react-scripts build
3:23:37 PM: Creating an optimized production build…
3:23:37 PM: Browserslist: caniuse-lite is outdated. Please run:
3:23:37 PM: npx update-browserslist-db@latest
3:23:37 PM: Why you should do it regularly: GitHub - browserslist/update-db: CLI tool to update caniuse-lite to refresh target browsers from Browserslist config
3:23:38 PM: Failed to compile.
3:23:38 PM:
3:23:38 PM: Module not found: Error: Can’t resolve ‘./pages/Home/Home’ in ‘/opt/build/repo/src’
3:23:38 PM: ​
3:23:38 PM: build.command failed
3:23:38 PM: ────────────────────────────────────────────────────────────────
3:23:38 PM: ​
3:23:38 PM: Error message
3:23:38 PM: Command failed with exit code 1: npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
3:23:38 PM: ​
3:23:38 PM: Error location
3:23:38 PM: In Build command from Netlify app:
3:23:38 PM: npm run build
3:23:38 PM: ​
3:23:38 PM: Resolved config
3:23:38 PM: build:
3:23:38 PM: command: npm run build
3:23:38 PM: commandOrigin: ui
3:23:38 PM: publish: /opt/build/repo/build
3:23:38 PM: publishOrigin: ui
3:23:39 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:23:39 PM: Failing build: Failed to build site
3:23:39 PM: Finished processing build request in 30.552s

screenshot

Hi @markohanesian, thanks for the post.

The error is caused by the quoted text above from your build logs.
Kindly make sure the path to Home file is valid.

If you are still having problems figuring it out, if possible provide a link to your repository so that I help with the debugging.

Thanks.

I found the issue - the path was correct on my local repo, but for some reason on Github it was never updated despite the working tree being clean. I deleted the lower case home/home on Github and pushed the correct path and it worked - thank you

1 Like

Hi @markohanesian, thanks for the feedback.
Glad to know my suggestion helped you to figure out the problem.

@clarnx I’m facing the same problem can you please solve my issue too.

Attach your build log please, that will be easiest for us.

1 Like

Hi @rishavbhadani sorry to hear you are facing a problem similar to the original poster’s problem.
As @SamO stated kindly provide your build logs so that we can help with the debugging.
Thanks.