Build script returned non-zero exit code: 2

Netlify site name: noona.is

I’m facing a build error: Error running command: Build script returned non-zero exit code: 2
Local build works and it works as well via the Netlify Docker image: https://github.com/netlify/build-image#running-locally

I found a similar issue but there doesn’t seem to be a sufficient solution here: Failed during stage 'building site': Build script returned non-zero exit code: 2

Is there a way to get more detailed error of what’s happening?

Build log
12:49:53 PM: Build ready to start
12:49:54 PM: build-image version: b0258b965567defc4a2d7e2f2dec2e00c8f73ad6
12:49:54 PM: build-image tag: v3.4.1
12:49:54 PM: buildbot version: c14f8ac04f7535496782ceb786d06f5741c8ed0f
12:49:55 PM: Fetching cached dependencies
12:49:55 PM: Failed to fetch cache, continuing with build
12:49:55 PM: Starting to prepare the repo for build
12:49:55 PM: No cached dependencies found. Cloning fresh repo
12:49:55 PM: git clone noona-hq/timatorg-web
12:49:56 PM: Preparing Git Reference refs/heads/qa
12:49:58 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: β€˜build’ versus β€˜build/’ in the Netlify UI
12:49:58 PM: Starting build script
12:49:58 PM: Installing dependencies
12:49:58 PM: Python version set to 2.7
12:49:59 PM: Downloading and installing node v10.22.1…
12:49:59 PM: Downloading nodejs/dist/v10.22.1/node-v10.22.1-linux-x64.tar.xz…
12:49:59 PM: Computing checksum with sha256sum
12:49:59 PM: Checksums matched!
12:50:02 PM: Now using node v10.22.1 (npm v6.14.6)
12:50:02 PM: Started restoring cached build plugins
12:50:02 PM: Finished restoring cached build plugins
12:50:02 PM: Attempting ruby version 2.6.2, read from environment
12:50:03 PM: Using ruby version 2.6.2
12:50:04 PM: Using PHP version 5.6
12:50:04 PM: 5.2 is already installed.
12:50:04 PM: Using Swift version 5.2
12:50:04 PM: Started restoring cached node modules
12:50:04 PM: Finished restoring cached node modules
12:50:04 PM: Started restoring cached yarn cache
12:50:04 PM: Finished restoring cached yarn cache
12:50:04 PM: Installing yarn at version 1.13.0
12:50:04 PM: Installing Yarn!
12:50:04 PM: > Downloading tarball…
12:50:04 PM: [1/2]: yarn/downloads/1.13.0/yarn-v1.13.0.tar.gz --> /tmp/yarn.tar.gz.MIF9JgKHvN
12:50:04 PM: % Total % Received % Xferd Average Speed Time Time Time Current
12:50:04 PM: Dload Upload Total Spent Left Speed
12:50:04 PM: 0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0
12:50:04 PM: 100 80 100 80 0 0 243 0 --:–:-- --:–:-- --:–:-- 243
12:50:04 PM: 0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0
12:50:04 PM: 100 93 100 93 0 0 133 0 --:–:-- --:–:-- --:–:-- 300
12:50:05 PM: 100 643 100 643 0 0 593 0 0:00:01 0:00:01 --:–:-- 593
12:50:05 PM: 3 1142k 3 43970 0 0 31617 0 0:00:36 0:00:01 0:00:35 31617
12:50:05 PM: 100 1142k 100 1142k 0 0 756k 0 0:00:01 0:00:01 --:–:-- 9315k
12:50:05 PM: [2/2]: yarnpkg/downloads/1.13.0/yarn-v1.13.0.tar.gz.asc --> /tmp/yarn.tar.gz.MIF9JgKHvN.asc
12:50:05 PM: 100 84 100 84 0 0 3123 0 --:–:-- --:–:-- --:–:-- 3123
12:50:05 PM: 100 97 100 97 0 0 1781 0 --:–:-- --:–:-- --:–:-- 1781
12:50:05 PM: 100 647 100 647 0 0 3478 0 --:–:-- --:–:-- --:–:-- 3478
12:50:05 PM: 100 832 100 832 0 0 3663 0 --:–:-- --:–:-- --:–:-- 3663
12:50:05 PM: > Verifying integrity…
12:50:06 PM: gpg: Signature made Tue 18 Dec 2018 04:04:55 PM UTC using RSA key ID B6FF4DE3
12:50:06 PM: gpg: Good signature from β€œYarn Packaging yarn@dan.cx”
12:50:06 PM: gpg: Note: This key has expired!
12:50:06 PM: Primary key fingerprint: 72EC F46A 56B4 AD39 C907 BBB7 1646 B01B 86E5 0310
12:50:06 PM: Subkey fingerprint: E219 30C4 D0A4 AA46 1858 1F7A E074 D16E B6FF 4DE3
12:50:06 PM: > GPG signature looks good
12:50:06 PM: > Extracting to ~/.yarn…
12:50:06 PM: > Adding to PATH... 12:50:06 PM: > Successfully installed Yarn 1.13.0! Please open another terminal where the `yarn` command will now be available. 12:50:07 PM: Installing NPM modules using Yarn version 1.13.0 12:50:07 PM: yarn install v1.13.0 12:50:07 PM: [1/4] Resolving packages... 12:50:08 PM: [2/4] Fetching packages... 12:50:34 PM: info fsevents@2.1.2: The platform "linux" is incompatible with this module. 12:50:34 PM: info "fsevents@2.1.2" is an optional dependency and failed compatibility check. Excluding it from installation. 12:50:34 PM: info fsevents@1.2.13: The platform "linux" is incompatible with this module. 12:50:34 PM: info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation. 12:50:34 PM: info fsevents@2.1.3: The platform "linux" is incompatible with this module. 12:50:34 PM: info "fsevents@2.1.3" is an optional dependency and failed compatibility check. Excluding it from installation. 12:50:34 PM: [3/4] Linking dependencies... 12:50:34 PM: warning " > react-apollo@2.5.8" has unmet peer dependency "apollo-client@^2.6.3". 12:50:34 PM: warning " > react-dates@21.8.0" has unmet peer dependency "@babel/runtime@^7.0.0". 12:50:34 PM: warning " > react-dates@21.8.0" has unmet peer dependency "react-with-direction@^1.3.1". 12:50:34 PM: warning "react-dates > react-with-styles@4.1.0" has unmet peer dependency "@babel/runtime@^7.0.0". 12:50:34 PM: warning "react-dates > react-with-styles-interface-css@6.0.0" has unmet peer dependency "@babel/runtime@^7.0.0". 12:50:34 PM: warning " > react-ga@2.7.0" has unmet peer dependency "prop-types@^15.6.0". 12:50:46 PM: [4/4] Building fresh packages... 12:50:47 PM: Done in 39.93s. 12:50:47 PM: NPM modules installed using Yarn 12:50:47 PM: Started restoring cached go cache 12:50:47 PM: Finished restoring cached go cache 12:50:47 PM: Installing Go version 1.12 12:50:53 PM: unset GOOS; 12:50:53 PM: unset GOARCH; 12:50:53 PM: export GOROOT='/opt/buildhome/.gimme_cache/versions/go1.12.linux.amd64'; 12:50:53 PM: export PATH="/opt/buildhome/.gimme_cache/versions/go1.12.linux.amd64/bin:{PATH}";
12:50:53 PM: go version >&2;
12:50:53 PM: export GIMME_ENV="/opt/buildhome/.gimme_cache/env/go1.12.linux.amd64.env"
12:50:53 PM: go version go1.12 linux/amd64
12:50:53 PM: Installing missing commands
12:50:53 PM: Verify run directory
12:50:54 PM: ​
12:50:54 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
12:50:54 PM: β”‚ Netlify Build β”‚
12:50:54 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
12:50:54 PM: ​
12:50:54 PM: ❯ Version
12:50:54 PM: @netlify/build 4.4.0
12:50:54 PM: ​
12:50:54 PM: ❯ Flags
12:50:54 PM: deployId: 5f747ef1462a7300078fe606
12:50:54 PM: mode: buildbot
12:50:54 PM: ​
12:50:54 PM: ❯ Current directory
12:50:54 PM: /opt/build/repo
12:50:54 PM: ​
12:50:54 PM: ❯ Config file
12:50:54 PM: /opt/build/repo/netlify.toml
12:50:54 PM: ​
12:50:54 PM: ❯ Context
12:50:54 PM: branch-deploy
12:50:54 PM: ​
12:50:54 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
12:50:54 PM: β”‚ 1. build.command from netlify.toml β”‚
12:50:54 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
12:50:54 PM: ​
12:50:54 PM: yarn build 12:50:54 PM: yarn run v1.13.0 12:50:55 PM: react-scripts build && cp _redirects build/
12:50:56 PM: Creating an optimized production build…
12:52:34 PM:
12:52:34 PM: Treating warnings as errors because process.env.CI = true.
12:52:34 PM: Most CI servers set it automatically.
12:52:34 PM:
12:52:34 PM: Failed to compile.
12:52:34 PM:
12:52:34 PM: ./src/scenes/landing/MapContainer.js
12:52:34 PM: Line 186:3: Number prototype is read only, properties should not be added no-extend-native
12:52:34 PM: Line 193:3: Number prototype is read only, properties should not be added no-extend-native
12:52:34 PM: ./src/timatorg-utils/StringUtils.js
12:52:34 PM: Line 42:22: Unnecessary escape character: [ no-useless-escape
12:52:34 PM: Line 42:47: Unnecessary escape character: [ no-useless-escape
12:52:34 PM: ./src/serviceWorker.js
12:52:34 PM: Line 42:80: Unexpected string concatenation of literals no-useless-concat
12:52:34 PM: Line 67:81: Unexpected string concatenation of literals no-useless-concat
12:52:34 PM: ./src/Navigator.js
12:52:34 PM: Line 51:9: The β€˜fetchUser’ function makes the dependencies of useEffect Hook (at line 69) change on every render. To fix this, wrap the β€˜fetchUser’ definition into its own useCallback() Hook react-hooks/exhaustive-deps
12:52:34 PM: Line 51:9: The β€˜fetchUser’ function makes the dependencies of useEffect Hook (at line 93) change on every render. To fix this, wrap the β€˜fetchUser’ definition into its own useCallback() Hook react-hooks/exhaustive-deps
12:52:34 PM: error Command failed with exit code 1.
12:52:34 PM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
12:52:34 PM: ​
12:52:34 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
12:52:34 PM: β”‚ β€œbuild.command” failed β”‚
12:52:34 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
12:52:34 PM: ​
12:52:34 PM: Error message
12:52:34 PM: Command failed with exit code 1: yarn build
12:52:34 PM: ​
12:52:34 PM: Error location
12:52:34 PM: In build.command from netlify.toml:
12:52:34 PM: yarn build
12:52:34 PM: ​
12:52:34 PM: Resolved config
12:52:34 PM: build:
12:52:34 PM: command: yarn build
12:52:34 PM: commandOrigin: config
12:52:34 PM: environment:
12:52:34 PM: - API_URL
12:52:34 PM: - NODE_ENV
12:52:34 PM: - NPM_TOKEN
12:52:34 PM: - REACT_APP_BUGSNAG_KEY
12:52:34 PM: - REACT_APP_GRAPHQL_ENDPOINT
12:52:34 PM: - REACT_APP_MAPBOX_TOKEN
12:52:34 PM: - REACT_APP_SENTRY_KEY
12:52:34 PM: publish: /opt/build/repo/build
12:52:34 PM: headers:
12:52:34 PM: - for: /* values: Cache-Control: β€˜public, max-age=0, must-revalidate’ redirects: - from: /* status: 200 to: /index.htmlCaching artifacts
12:52:34 PM: Started saving node modules
12:52:34 PM: Finished saving node modules
12:52:34 PM: Started saving build plugins
12:52:34 PM: Finished saving build plugins
12:52:34 PM: Started saving yarn cache
12:52:34 PM: Finished saving yarn cache
12:52:34 PM: Started saving pip cache
12:52:34 PM: Finished saving pip cache
12:52:34 PM: Started saving emacs cask dependencies
12:52:34 PM: Finished saving emacs cask dependencies
12:52:34 PM: Started saving maven dependencies
12:52:34 PM: Finished saving maven dependencies
12:52:34 PM: Started saving boot dependencies
12:52:34 PM: Finished saving boot dependencies
12:52:34 PM: Started saving go dependencies
12:52:36 PM: Finished saving go dependencies
12:52:39 PM: Error running command: Build script returned non-zero exit code: 2
12:52:39 PM: Failing build: Failed to build site
12:52:39 PM: Failed during stage β€˜building site’: Build script returned non-zero exit code: 2
12:52:39 PM: Finished processing build request in 2m44.864718139s

I tried limiting the memory in docker run by modifying the start-image.sh script as seen below. It still succeeds building locally.

#!/bin/bash

BASE_PATH=$(pwd)
REPO_PATH=$(cd $1 && pwd)
: ${NETLIFY_IMAGE="netlify/build:xenial"}

docker run --rm -t -i \
        -m 3g \
        -e NODE_VERSION \
        -e NPM_VERSION \
        -e RUBY_VERSION \
        -e YARN_VERSION \
        -e HUGO_VERSION \
        -e PHP_VERSION \
        -e GO_VERSION \
        -e SWIFT_VERSION \
        -e PYTHON_VERSION \
        -v ${REPO_PATH}:/opt/repo \
        -v ${BASE_PATH}/run-build.sh:/opt/build-bin/build \
        -v ${BASE_PATH}/run-build-functions.sh:/opt/build-bin/run-build-functions.sh \
        $NETLIFY_IMAGE /bin/bash
12:50:56 PM: Creating an optimized production build…
12:52:34 PM:
12:52:34 PM: Treating warnings as errors because process.env.CI = true.
12:52:34 PM: Most CI servers set it automatically.

hi there, this might be a useful read:

Thanks. It works to set the CI environment variable to false/undefined.

In your opinion, would this be classified as a bug from create-react-app? Should it be able to handle the CI environment variable to be truthy?

The answer is β€œit depends” - some people expect that to work differently than others. Too bad it is a β€œde-facto” standard rather than one that is documented and universally agreed upon.

From their point of view, they are doing what they intend. From others’ points of view, such as ours, they are doing it differently than the people who created the convention perhaps intended…

I suspect if you file a bug on their project, they’ll tell you the same thing, but I’m not sure :slight_smile:

Interesting. Is this a requirement for all React apps that are created with create-react-app? To specify CI= prior to their build?

Nope! Only ones that don’t run without warnings, which you want to run in a CI system like Travis or Netlify :slight_smile:

Ah, got it. Thanks :grinning:

I found this post to be a good read if anyone’s interested in diving deeper: How to fix build failures with `create-react-app` in production

2 Likes

Hi,
I am new here and learning. When I tried to add the new field to the existing Setup, The build was failed and error returned is [Build script returned non-zero exit code: 2].

appreciate for the quick Help

screenshots



just followed the previous code add the field

hi there, can you please paste your full build log with the exact error? thanks!