Home
Support Forums

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

Hey guys ,
So I’ve had this issue before and other sites and I solved it but simply putting
CI= npm run build
in build command

anyway , in this project not that its just not working but the website was up and running, it was just a react app until I’v added a server side with node and used concurrently to run them both and pushed to Github the deployment is failing ever since.

6:14:03 PM: $ CI= npm run build
6:14:03 PM: npm ERR! Missing script: "build"
6:14:03 PM: npm ERR!
6:14:03 PM: npm ERR! To see a list of scripts, run:
6:14:03 PM: npm ERR!   npm run
6:14:03 PM: npm ERR! A complete log of this run can be found in:
6:14:03 PM: npm ERR!     /opt/buildhome/.npm/_logs/2021-10-29T15_14_03_672Z-debug.log
6:14:03 PM: ​
6:14:03 PM: ────────────────────────────────────────────────────────────────
6:14:03 PM:   "build.command" failed                                        
6:14:03 PM: ────────────────────────────────────────────────────────────────
6:14:03 PM: ​
6:14:03 PM:   Error message
6:14:03 PM:   Command failed with exit code 1: CI= npm run build
6:14:03 PM: ​
6:14:03 PM:   Error location
6:14:03 PM:   In Build command from Netlify app:
6:14:03 PM:   CI= npm run build
6:14:03 PM: ​
6:14:03 PM:   Resolved config
6:14:03 PM:   build:
6:14:03 PM:     command: CI= npm run build
6:14:03 PM:     commandOrigin: ui
6:14:03 PM:     publish: /opt/build/repo/client/build
6:14:03 PM:     publishOrigin: ui
6:14:04 PM: Caching artifacts
6:14:04 PM: Started saving node modules
6:14:04 PM: Finished saving node modules
6:14:04 PM: Started saving build plugins
6:14:04 PM: Finished saving build plugins
6:14:04 PM: Started saving pip cache
6:14:04 PM: Finished saving pip cache
6:14:04 PM: Started saving emacs cask dependencies
6:14:04 PM: Finished saving emacs cask dependencies
6:14:04 PM: Started saving maven dependencies
6:14:04 PM: Finished saving maven dependencies
6:14:04 PM: Started saving boot dependencies
6:14:04 PM: Finished saving boot dependencies
6:14:04 PM: Started saving rust rustup cache
6:14:04 PM: Finished saving rust rustup cache
6:14:04 PM: Started saving go dependencies
6:14:04 PM: Finished saving go dependencies
6:14:06 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
6:14:06 PM: Creating deploy upload records
6:14:06 PM: Failing build: Failed to build site
6:14:06 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
6:14:06 PM: Finished processing build request in 31.297798386s

everything works in the same project before, I’v browsed many similar questions yet nothing helps.
any ideas ? help is much appreciated :slight_smile:

Your package.json doesn’t have the build command. You’d need to add one.

although it says that , but it does have build script.
not on the outer package.json of the server though , but on the client.

and the think is I’ve deployed apps this way before and it worked great.

In that case you need to set the client folder as the base path in Netlify settings.

If you don’t think that’s it, could you share your repo?

if you mean by setting the build command to
client/build instead of just build I also did that , and made sure that my other working repo that was build in the same way so also similar and still didn’t work.

this is the repo

you can see that my last 5+ commits were only for this matter…

and thanks

No build command would be npm run build but base path would be client.

yeah exactly , nothing works.
I have my build command as
CI= npm run build
to avoid issues , this is all of my projects.
and for the path I tried build and client and client/build

Could you share the deploy log links with each of those cases?

this is the last deploy for example made just now.

6:40:33 PM: ────────────────────────────────────────────────────────────────
6:40:33 PM:   1. Build command from Netlify app                             
6:40:33 PM: ────────────────────────────────────────────────────────────────
6:40:33 PM: ​
6:40:33 PM: $ CI= npm run build
6:40:34 PM: npm ERR! Missing script: "build"
6:40:34 PM: npm ERR!
6:40:34 PM: npm ERR! To see a list of scripts, run:
6:40:34 PM: npm ERR!   npm run
6:40:34 PM: npm ERR! A complete log of this run can be found in:
6:40:34 PM: npm ERR!     /opt/buildhome/.npm/_logs/2021-10-30T15_40_34_182Z-debug.log
6:40:34 PM: ​
6:40:34 PM: ────────────────────────────────────────────────────────────────
6:40:34 PM:   "build.command" failed                                        
6:40:34 PM: ────────────────────────────────────────────────────────────────
6:40:34 PM: ​
6:40:34 PM:   Error message
6:40:34 PM:   Command failed with exit code 1: CI= npm run build
6:40:34 PM: ​
6:40:34 PM:   Error location
6:40:34 PM:   In Build command from Netlify app:
6:40:34 PM:   CI= npm run build
6:40:34 PM: ​
6:40:34 PM:   Resolved config
6:40:34 PM:   build:
6:40:34 PM:     command: CI= npm run build
6:40:34 PM:     commandOrigin: ui
6:40:34 PM:     publish: /opt/build/repo/client
6:40:34 PM:     publishOrigin: ui
6:40:34 PM: Caching artifacts
6:40:34 PM: Started saving node modules
6:40:34 PM: Finished saving node modules
6:40:34 PM: Started saving build plugins
6:40:34 PM: Finished saving build plugins
6:40:34 PM: Started saving pip cache
6:40:34 PM: Finished saving pip cache
6:40:34 PM: Started saving emacs cask dependencies
6:40:34 PM: Finished saving emacs cask dependencies
6:40:34 PM: Started saving maven dependencies
6:40:34 PM: Finished saving maven dependencies
6:40:34 PM: Started saving boot dependencies
6:40:34 PM: Finished saving boot dependencies
6:40:34 PM: Started saving rust rustup cache
6:40:34 PM: Finished saving rust rustup cache
6:40:34 PM: Started saving go dependencies
6:40:34 PM: Finished saving go dependencies
6:40:37 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
6:40:37 PM: Creating deploy upload records
6:40:37 PM: Failing build: Failed to build site
6:40:37 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
6:40:37 PM: Finished processing build request in 34.725593321s

Screen Shot 2021-10-30 at 18.43.17 PM

No I meant the link to this deploy, not the log itself.

Oh ,
I didn’t’t know you can share that, would that be it ?
https://app.netlify.com/sites/matimetracking/deploys/617d67506961c5ecea72c054
or
https://app.netlify.com/sites/matimetracking/deploys

So yeah, it’s simple, you’ve set the publish path as client, while the base path should be set as client.

I’m sorry I’m not sure I totally got it

Base directory and publish directory are 2 different things. You need to set the base directory as client and publish directory should be build.

1 Like

haha yep this is exactly what I was missing, I just checked one of my repos and it sure does have the base directory.
/client
apparently I was trying to manually write build/client in the publish directory without paying attention to the base directory

Thanks!
I really appreciate the help.