Home
Support Forums

Consistent Build Failure

PLEASE help us help you by writing a good post!

  • we need to know your netlify site name. Example: gifted-antelope-58b104.netlify.app
  • DNS issues? Tell us the custom domain, tell us the error message! We can’t help if we don’t know your domain.
  • Build problems? Link or paste the FULL build log & build settings screenshot

The better the post - the faster the answer.
Hello,

I’ve been trying to solve this issue for over a week now. I’m trying to deploy my app on netlify, but I keep getting “build failed”, sometimes with exit code 127, sometimes exit code 1, sometimes exit code 2, other times I have an infinite loop npm run build. I’ve tried all suggestions I found online, non of them is working.
Site name: affectionate-shirley-47df6f

Here’s my package.json script:

“scripts”: {
“build”: “npm run build”,
“start”: “npm run start”,
“test”: “npm run test”
},

Here’s my netlify.toml build script:
[build]
base = “”
publish = “build”
command = “CI= npm run build”

Here’s my out put:

5:09:29 PM: Started restoring cached go cache
5:09:29 PM: Finished restoring cached go cache
5:09:29 PM: go version go1.16.5 linux/amd64
5:09:29 PM: go version go1.16.5 linux/amd64
5:09:29 PM: Installing missing commands
5:09:29 PM: Verify run directory
5:09:30 PM: ​
5:09:30 PM: ────────────────────────────────────────────────────────────────
5:09:30 PM: Netlify Build
5:09:30 PM: ────────────────────────────────────────────────────────────────
5:09:30 PM: ​
5:09:30 PM: ❯ Version
5:09:30 PM: @netlify/build 18.7.3
5:09:30 PM: ​
5:09:30 PM: ❯ Flags
5:09:30 PM: baseRelDir: true
5:09:30 PM: buildId: 61328ea9f30d000008d32a51
5:09:30 PM: deployId: 61328ea9f30d000008d32a54
5:09:30 PM: ​
5:09:30 PM: ❯ Current directory
5:09:30 PM: /opt/build/repo
5:09:30 PM: ​
5:09:30 PM: ❯ Config file
5:09:30 PM: /opt/build/repo/netlify.toml
5:09:30 PM: ​
5:09:30 PM: ❯ Context
5:09:30 PM: production
5:09:30 PM: ​
5:09:30 PM: ────────────────────────────────────────────────────────────────
5:09:30 PM: 1. build.command from netlify.toml
5:09:30 PM: ────────────────────────────────────────────────────────────────
5:09:30 PM: ​
5:09:30 PM: $ CI=true npm run build
5:09:30 PM: > frontend@0.1.0 build
5:09:30 PM: > npm run build
5:09:30 PM: > frontend@0.1.0 build
5:09:30 PM: > npm run build
5:09:31 PM: > frontend@0.1.0 build
5:09:31 PM: > npm run build
5:09:31 PM: > frontend@0.1.0 build
5:09:31 PM: > npm run build
5:09:32 PM: > frontend@0.1.0 build
5:09:32 PM: > npm run build
5:09:32 PM: > frontend@0.1.0 build
5:09:32 PM: > npm run build
5:09:32 PM: > frontend@0.1.0 build
5:09:32 PM: > npm run build
5:09:33 PM: > frontend@0.1.0 build
5:09:33 PM: > npm run build
5:09:33 PM: > frontend@0.1.0 build
5:09:33 PM: > npm run build
5:09:33 PM: > frontend@0.1.0 build
5:09:33 PM: > npm run build
5:09:34 PM: > frontend@0.1.0 build
5:09:34 PM: > npm run build
5:09:34 PM: > frontend@0.1.0 build
5:09:34 PM: > npm run build
5:09:34 PM: > frontend@0.1.0 build
5:09:34 PM: > npm run build
5:09:35 PM: > frontend@0.1.0 build
5:09:35 PM: > npm run build
5:09:35 PM: > frontend@0.1.0 build
5:09:35 PM: > npm run build
5:09:35 PM: > frontend@0.1.0 build
5:09:35 PM: > npm run build
5:09:36 PM: > frontend@0.1.0 build
5:09:36 PM: > npm run build
5:09:36 PM: > frontend@0.1.0 build
5:09:36 PM: > npm run build
5:09:36 PM: > frontend@0.1.0 build
5:09:36 PM: > npm run build
5:09:37 PM: > frontend@0.1.0 build
5:09:37 PM: > npm run build
5:09:37 PM: > frontend@0.1.0 build
5:09:37 PM: > npm run build
5:09:37 PM: > frontend@0.1.0 build
5:09:37 PM: > npm run build
5:09:38 PM: > frontend@0.1.0 build
5:09:38 PM: > npm run build
5:09:38 PM: > frontend@0.1.0 build
5:09:38 PM: > npm run build
5:09:38 PM: > frontend@0.1.0 build
5:09:38 PM: > npm run build
5:09:39 PM: > frontend@0.1.0 build
5:09:39 PM: > npm run build
5:09:39 PM: > frontend@0.1.0 build
5:09:39 PM: > npm run build
5:09:40 PM: > frontend@0.1.0 build
5:09:40 PM: > npm run build
5:09:40 PM: > frontend@0.1.0 build
5:09:40 PM: > npm run build
5:09:40 PM: > frontend@0.1.0 build

Hi @palin

Can you share your git repository to assist in debugging?

Git repo is private. I know the issues are package.json and the build command.

The build command is calling itself.

You need something like:

"scripts": {
  "build": "astro build"
}

so that when you npm run build the build command astro build is executed.

Change astro build to the command of your framework (React, Vue, Nuxt, Next, etc.)

Hi, thanks for looking into this issue. I realised the “build” : “npm run build” was what was giving me infinite loop. I had to delete my entire project locally, started over to create a react app and copy the custome files. I’m still having build issues. Here’s my error, and my package.json scripts:

netlify.toml:
[build]
base = “”
publish = “build”
command = “CI= npm run build”

package.json:
“redux-thunk”: “^2.3.0”
},
“scripts”: {
“start”: “react-scripts start”,
“build”: “react-scripts build”,
“test”: “react-scripts test”,
“eject”: “react-scripts eject”
},

Output:
9:48:01 PM: ❯ Flags
9:48:01 PM: baseRelDir: true
9:48:01 PM: buildId: 6132d045988a0220f474708a
9:48:01 PM: deployId: 6132d045988a0220f474708c
9:48:01 PM: ​
9:48:01 PM: ❯ Current directory
9:48:01 PM: /opt/build/repo
9:48:01 PM: ​
9:48:01 PM: ❯ Config file
9:48:01 PM: No config file was defined: using default values.
9:48:01 PM: ​
9:48:01 PM: ❯ Context
9:48:01 PM: production
9:48:01 PM: ​
9:48:01 PM: ────────────────────────────────────────────────────────────────
9:48:01 PM: 1. Build command from Netlify app
9:48:01 PM: ────────────────────────────────────────────────────────────────
9:48:01 PM: ​
9:48:01 PM: $ CI=’’ npm run build
9:48:02 PM: npm ERR! Missing script: “build”
9:48:02 PM: npm ERR!
9:48:02 PM: npm ERR! To see a list of scripts, run:
9:48:02 PM: npm ERR! npm run
9:48:02 PM: npm ERR! A complete log of this run can be found in:
9:48:02 PM: npm ERR! /opt/buildhome/.npm/_logs/2021-09-04T01_48_02_202Z-debug.log
9:48:02 PM: ​
9:48:02 PM: ────────────────────────────────────────────────────────────────
9:48:02 PM: “build.command” failed
9:48:02 PM: ────────────────────────────────────────────────────────────────
9:48:02 PM: ​
9:48:02 PM: Error message
9:48:02 PM: Command failed with exit code 1: CI=’’ npm run build
9:48:02 PM: ​
9:48:02 PM: Error location
9:48:02 PM: In Build command from Netlify app:
9:48:02 PM: CI=’’ npm run build
9:48:02 PM: ​
9:48:02 PM: Resolved config
9:48:02 PM: build:
9:48:02 PM: command: CI=’’ npm run build
9:48:02 PM: commandOrigin: ui
9:48:02 PM: publish: /opt/build/repo/build
9:48:02 PM: publishOrigin: ui
9:48:02 PM: Caching artifacts
9:48:02 PM: Started saving build plugins
9:48:02 PM: Finished saving build plugins
9:48:02 PM: Started saving pip cache
9:48:02 PM: Finished saving pip cache
9:48:02 PM: Started saving emacs cask dependencies
9:48:02 PM: Finished saving emacs cask dependencies
9:48:02 PM: Started saving maven dependencies
9:48:02 PM: Finished saving maven dependencies
9:48:02 PM: Started saving boot dependencies
9:48:02 PM: Finished saving boot dependencies
9:48:02 PM: Started saving rust rustup cache
9:48:02 PM: Finished saving rust rustup cache
9:48:02 PM: Started saving go dependencies
9:48:02 PM: Finished saving go dependencies
9:48:05 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:48:05 PM: Creating deploy upload records
9:48:05 PM: Failing build: Failed to build site
9:48:05 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
9:48:05 PM: Finished processing build request in 14.747461475s

That appears correct.

You can find a bare-bones react repository at coelmay/netlify-react-bare (using yarn not npm, but principle is the same.)

Thank you. I tried yarn seeing that’s what I’m using on my local project, now I get “yarn command not found” Any other idea you might have? I can’t find any solution online

Check out the yarn docs. If you don’t have a yarn.lock you will need to set an environment variable to tell Netlify to use it.

I have it at the root directory. Do I have to use environmental variables for netlify to see it?

If you have a yarn.lock in you project root, the Netlify build system should see it and use yarn.

this is my project tree. I’m not sure what else to do to fix this problem

Try a “Clear cache and deploy site” from the deploys page

Screen Shot 2021-07-26 at 8.58.58 am

Failing that, without the option to see and test deploying your code, there isn’t a lot more I can offer in terms of solutions.

Hi, thanks for your help so far. I’ve cleared cache several times, deleted the app from netlify and redeployed several times. It’s still not working. Is there any way someone can look into my project? i just don’t know what I’m missing.

If you make your repository public.

Thanks. Here’s my repo

The default branch is main which contains only a README.md. The master branch contains all the code. Suggest changing the default branch to master and deleting main.

1 Like

Thank you! So I checked and changed it to master branch, that helped to trigger automatic builds. I also installed netlify-cli dependencies (I’m not sure if that helped). After these steps, I tried again, the build still failed with a different error:

11:09:29 PM: error Command failed with exit code 1.
11:09:29 PM: info Visit yarn run | Yarn for documentation about this command.
11:09:29 PM: ​
11:09:29 PM: ────────────────────────────────────────────────────────────────
11:09:29 PM: “build.command” failed
11:09:29 PM: ────────────────────────────────────────────────────────────────
11:09:29 PM: ​
11:09:29 PM: Error message
11:09:29 PM: Command failed with exit code 1: yarn build
11:09:29 PM: ​
11:09:29 PM: Error location
11:09:29 PM: In build.command from netlify.toml:
11:09:29 PM: yarn build
11:09:29 PM: ​
11:09:29 PM: Resolved config
11:09:29 PM: build:
11:09:29 PM: command: yarn build
11:09:29 PM: commandOrigin: config
11:09:29 PM: publish: /opt/build/repo/build
11:09:29 PM: publishOrigin: config

I subsequently changed the build command in netlify.toml file to CI= npm run build, and its working now.

Thank you