Search code examples
reactjsnetlify

Build script returned non-zero exit code: 2 - React


Yes, I've searched for the solution but I can't find how to deploy my site from Netlify using react app. My app is split from the repo into client and server. I need to run the client folder. I've also tried CI= npm run build, changing the environment variable to false, what else can I do? Here's the log. I've ran the build locally also.

Github repo - https://github.com/jerednav/mindful-list

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

Solution

  • You need to specify base directory either in netlify settings. Go to Settings -> Build and Deploy -> Edit Settings and fill it with client.

    Or you can create netlify.toml in project dir with following config

    [build]
      # Directory to change to before starting a build.
      # This is where we will look for package.json/.nvmrc/etc.
      # If not set, defaults to the root directory.
      base = "client"