"build.command" failed - can not deploy my React project

I do not know what should I do. I really strugle for a long time with this.

here my React site works perfectly: https://648953f31d9ae06517258d7a--magicocoding.netlify.app/

when I start it offline from VS code it works perfectly: GitHub - Markomanis/5

But once I try to deploy I face the error :frowning: Spent hours and non of the solutions here in forum helped my case.

@RandomUser24 For future reference you should post your entire build log, not just a screenshot. The section that you’ve screenshot is fairly useless and the real error will will be higher up in the log.

Have you tried running your npm run build command locally?

When I do I get the following error:

image

You’re running react-scripts build but I don’t see react-scripts in your dependencies:

image

I notice you have another sub-folder with another package.json too, and it’s likely that may be the true source of your issues.

Netlify will only automatically install the dependencies of the package.json file that it finds in your Base directory

Yes sir, @nathanmartin that works once you are in the Client folder.
When I npm run build in Client folder it works fine.

Here is the entire log sir:
9:29:04 AM: Netlify Build
9:29:04 AM: ────────────────────────────────────────────────────────────────
9:29:04 AM: ​
9:29:04 AM: ❯ Version
9:29:04 AM: @netlify/build 29.12.1
9:29:04 AM: ​
9:29:04 AM: ❯ Flags
9:29:04 AM: baseRelDir: true
9:29:04 AM: buildId: 64896c213fcfe900085b83d2
9:29:04 AM: deployId: 64896c213fcfe900085b83d4
9:29:04 AM: ​
9:29:04 AM: ❯ Current directory
9:29:04 AM: /opt/build/repo
9:29:04 AM: ​
9:29:04 AM: ❯ Config file
9:29:04 AM: No config file was defined: using default values.
9:29:04 AM: ​
9:29:04 AM: ❯ Context
9:29:04 AM: production
9:29:04 AM: ​
9:29:04 AM: Build command from Netlify app
9:29:04 AM: ────────────────────────────────────────────────────────────────
9:29:04 AM: ​
9:29:04 AM: $ CI= npm run build
9:29:04 AM: > portfoliopro@1.0.0 build
9:29:04 AM: > react-scripts build
9:29:04 AM: sh: 1: react-scripts: not found
9:29:04 AM: ​
9:29:04 AM: β€œbuild.command” failed
9:29:04 AM: ────────────────────────────────────────────────────────────────
9:29:04 AM: ​
9:29:04 AM: Error message
9:29:04 AM: Command failed with exit code 127: CI= npm run build (Search results for '"non-zero exit code: 127"' - Netlify Support Forums)
9:29:04 AM: ​
9:29:04 AM: Error location
9:29:04 AM: In Build command from Netlify app:
9:29:04 AM: CI= npm run build
9:29:04 AM: ​
9:29:04 AM: Resolved config
9:29:04 AM: build:
9:29:04 AM: command: CI= npm run build
9:29:04 AM: commandOrigin: ui
9:29:04 AM: publish: /opt/build/repo/build
9:29:04 AM: publishOrigin: ui
9:29:05 AM: Failed during stage β€˜building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
9:29:05 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:29:05 AM: Failing build: Failed to build site
9:29:06 AM: Finished processing build request in 27.723s

See how it’s precisely the same error.

Make sure that your Basic build settings are set correctly, that you’re pointing Netlify to the right Base directory, and have the right Publish directory set etc.

But I do not know how to do that sir. I thought aswell issue is somewhere in the folder linkin but I have no idea how to fix it.

@RandomUser24 Unfortunately nobody else is going to do it for you, unless you hire assistance.

Netlify is largely a β€œself service” hosting provider, you have to understand what you’re working with.

I’ve explained what you need to do and linked to the documentation, you should have a read.

Well thank you for not helping me sir. Then I go and ask for refund. My project wokrs perfectly to the point when I try to deploy it to your server and it is my fault. Ok.

@RandomUser24 You can be angry at me, but it’s worth noting that I don’t work for Netlify, I’m just a member of the community.

I’ve tried to help you with your issue, but you seem to expect me to configure it for you?

If you want the assistance of Netlify staff you’ll have to wait, and if you’re on a paid plan you can submit a support ticket and wait for assistance there.

I’ve pulled your repository as linked, and executed it locally and that’s not the case.

If you do an npm install (in your root folder) and then do an npm run build (in your root folder), you’ll see the same thing as you’re seeing on Netlify.

If you’re expecting Netlify to go into the client folder and build/deploy that, then you need to configure Netlify to do so, by using the Basic build settings that I’ve linked to.

You literally didnt help me sir. Your reply was not helpfull at all.

sir I did that I will send you my settings in order to see it on your own

@RandomUser24 Excellent, that’d be useful instead of just asserting that I’m not trying to help you.

You seem to be angry that I can’t/won’t go into your build settings and set up your project for you, but as I say, there’s a limit to the support that you get here.

You shouldn’t be angry at a community that is trying to help you.

1 Like

I am not angry at you sir, just saying your reply was not helpful

The build settings that you’ve posted are saying:

  • Execute the build command in the root of the repository (as you have no Base directory set)
  • Run the command CI= npm run build
  • Send the folder client/build to the CDN

Does that seem correct to you?

As I stated originally, Netlify will install the dependencies of the package.json that it finds in your Base directory, which in this case is the root of the repository by default, as you’ve not specified anything else.

That particular package.json doesn’t contain any dependency for react-scripts.

Netlify doesn’t install the dependencies of any of your other package.json files.

It’s then running the npm run build command of that root package.json, which says to run react-scripts build, it then cannot find react-scripts and it errors.

If you want Netlify to install a different package.json or be in a different folder, you need to configure it as such, as I said originally.

I had it before set as Client and before name of the project. I created another repository in order to try it againt differently. GitHub - Markomanis/5 but at this point I do not know unfortunarelly how ti link it properly or which folder should I specify

I understand you sir but I do not know how to do it. I have 2 files package.json one in root dir and one is located in the Client. And this is my issue to be honnest I dont know how to move them or link them in so way that it would be possible to get properly to package.json which is located in the Client folder where are all react-scripts located

@RandomUser24 Sorry I’m not understanding, do you not know how to work with your project?

I do but I do not know how to configure it in order to be able Netlify to get properly into the package.json that is located in my Client folder where are all my scripts where the command npm run build can actually work

@RandomUser24 Is it only the client folder that you need to build & deploy?

When I run my project offline I do in the main root so I step out of the CLient where my backend is aswell and then I run npm start dev in order to both front end and back end ran properly. So client is not enough that’s I thought it is okay to have 2 package.json files have I cant even imagine how I would have done it with one both front end and back end