Build fails on Command failed with exit code 1 or Command failed with exit code 137

Hey there Netlify Support.

I’m running into an issue where my builds have started failing recently with two more generic error messages and no luck sorting out what went wrong.

I’m running a Gatsby site and have gone through all the basic build troubleshooting steps without much luck. The site builds locally and also if I clear cache before deploying which leads me to wonder if it’s something like this: [Support Guide] My site deploy fails unless Netlify's build cache is cleared

However none of these scenarios seem to match. I tried looking into Postinstall script fails using netlify-lambda to install function dependencies · Issue #227 · netlify/netlify-lambda · GitHub without much luck either. Has anyone run into something like this that might have any additional troubleshooting steps? Thanks in advance!

Build settings:
Base directory - Not set
Build command - npm run build && npm run build-server
Publish directory - public
Build status - Active

Site Id: aaf32c69-2461-4a89-bdac-9d80666fa758

(This is is a clone of our main site as our main site is on an old Build image and I am testing upgrading to the updated build image, but builds are currently failing on both)

11:09:48 AM: build-image version: d7b3813f01c06610bc1723ff1b22446513ee7941 (focal)
11:09:48 AM: build-image tag: v4.14.3
11:09:48 AM: buildbot version: f2613f2234a773b4fab58b5a3c03c743fe78f9bf
11:09:49 AM: Building without cache
11:09:49 AM: Starting to prepare the repo for build
11:09:49 AM: No cached dependencies found. Cloning fresh repo
11:09:49 AM: git clone https://github.com/submittable/www.submittable.com
11:09:53 AM: Preparing Git Reference pull/928/head
11:09:53 AM: Parsing package.json dependencies
11:09:55 AM: 
​
❯ Initial build environment
baseRelDir: true
branch: update/remove-plugin
context: deploy-preview
cwd: /opt/build/repo
featureFlags: []
mode: buildbot
repositoryRoot: /opt/build/repo
siteId: aaf32c69-2461-4a89-bdac-9d80666fa758
​
❯ UI build settings
baseRelDir: true
build:
  command: npm run build && npm run build-server
  environment:
    - NETLIFY_BUILD_DEBUG
    - NODE_ENV
    - NODE_VERSION
    - REVIEW_ID
    - YARN_VERSION
  publish: public
​
❯ Resolved build environment
branch: update/remove-plugin
buildDir: /opt/build/repo
configPath: /opt/build/repo/netlify.toml
context: deploy-preview
env: []
​
❯ Resolved config
build:
  command: npm run build && npm run build-server
  commandOrigin: config
  environment:
    - NETLIFY_BUILD_DEBUG
    - NODE_ENV
    - NODE_VERSION
    - REVIEW_ID
    - YARN_VERSION
  publish: /opt/build/repo/public
  publishOrigin: config
functionsDirectory: /opt/build/repo/lambda
11:09:55 AM: Starting build script
11:09:55 AM: Installing dependencies
11:09:55 AM: Python version set to 2.7
11:09:55 AM: v16.18.0 is already installed.
11:09:56 AM: Now using node v16.18.0 (npm v8.19.2)
11:09:56 AM: Enabling node corepack
11:09:56 AM: Started restoring cached build plugins
11:09:56 AM: Finished restoring cached build plugins
11:09:56 AM: Required ruby-2.7.1 is not installed.
11:09:56 AM: To install do: 'rvm install "ruby-2.7.1"'
11:09:56 AM: Attempting ruby version 2.7.1, read from .ruby-version file
11:09:56 AM: Required ruby-2.7.1 is not installed - installing.
11:09:57 AM: Searching for binary rubies, this might take some time.
11:09:57 AM: Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/20.04/x86_64/ruby-2.7.1.tar.bz2
11:09:57 AM: Checking requirements for ubuntu.
11:09:57 AM: Requirements installation successful.
11:09:57 AM: ruby-2.7.1 - #configure
11:09:57 AM: ruby-2.7.1 - #download
11:09:57 AM: ruby-2.7.1 - #validate archive
11:10:01 AM: ruby-2.7.1 - #extract
11:10:04 AM: ruby-2.7.1 - #validate binary
11:10:04 AM: ruby-2.7.1 - #setup
11:10:04 AM: ruby-2.7.1 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.7.1@global
11:10:04 AM: ruby-2.7.1 - #importing gemset /opt/buildhome/.rvm/gemsets/global.gems........................................
11:10:05 AM: ruby-2.7.1 - #generating global wrappers........
11:10:05 AM: ruby-2.7.1 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.7.1
11:10:05 AM: ruby-2.7.1 - #importing gemsetfile /opt/buildhome/.rvm/gemsets/default.gems evaluated to empty gem list
11:10:05 AM: ruby-2.7.1 - #generating default wrappers........
11:10:05 AM: Using /opt/buildhome/.rvm/gems/ruby-2.7.1
11:10:06 AM: Using ruby version 2.7.1
11:10:06 AM: Using PHP version 8.0
11:10:06 AM: WARNING: The environment variable 'NODE_ENV' is set to 'production'. Any 'devDependencies' in package.json will not be installed
11:10:06 AM: Started restoring cached yarn cache
11:10:06 AM: Finished restoring cached yarn cache
11:10:07 AM: No yarn workspaces detected
11:10:07 AM: Started restoring cached node modules
11:10:07 AM: Finished restoring cached node modules
11:10:07 AM: Installing NPM modules using Yarn version 1.22.19
11:10:07 AM: yarn install v1.22.19
11:10:07 AM: [1/4] Resolving packages...
11:10:08 AM: warning npm > node-gyp > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
11:10:08 AM: warning npm > node-gyp > request > har-validator@5.1.5: this library is no longer supported
11:10:09 AM: warning npm > node-gyp > request > uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
11:10:09 AM: [2/4] Fetching packages...
11:10:44 AM: [3/4] Linking dependencies...
11:10:44 AM: warning " > @reach/router@1.3.4" has incorrect peer dependency "react@15.x || 16.x || 16.4.0-alpha.0911da3".
11:10:44 AM: warning " > @reach/router@1.3.4" has incorrect peer dependency "react-dom@15.x || 16.x || 16.4.0-alpha.0911da3".
11:10:44 AM: warning "@reach/router > create-react-context@0.3.0" has incorrect peer dependency "react@^0.14.0 || ^15.0.0 || ^16.0.0".
11:10:44 AM: warning " > gatsby-link@4.24.1" has unmet peer dependency "@gatsbyjs/reach-router@^1.3.5".
11:10:44 AM: warning " > gatsby-plugin-image@2.24.0" has unmet peer dependency "gatsby-source-filesystem@^4.0.0-next".
11:10:44 AM: warning " > gatsby-plugin-mdx@3.20.0" has unmet peer dependency "@mdx-js/mdx@^1.0.0".
11:10:44 AM: warning " > gatsby-plugin-mdx@3.20.0" has unmet peer dependency "@mdx-js/react@^1.0.0".
11:10:44 AM: warning " > gatsby-transformer-sqip@4.24.0" has incorrect peer dependency "gatsby-source-contentful@^6.0.0-next".
11:10:44 AM: warning " > react-animate-on-scroll@2.1.5" has incorrect peer dependency "react@>= 15.4.1 < 17.0.0-0".
11:10:44 AM: warning " > react-scrolllock@5.0.1" has incorrect peer dependency "react@^16.3.0".
11:10:44 AM: warning " > slick-carousel@1.8.1" has unmet peer dependency "jquery@>=1.8.0".
11:10:44 AM: warning " > babel-preset-gatsby@1.14.0" has unmet peer dependency "core-js@^3.0.0".
11:10:44 AM: warning "gatsby > react-server-dom-webpack@0.0.0-experimental-c8b778b7f-20220825" has incorrect peer dependency "react@0.0.0-experimental-c8b778b7f-20220825".
11:10:44 AM: warning Workspaces can only be enabled in private projects.
11:10:55 AM: [4/4] Building fresh packages...
11:11:00 AM: success Saved lockfile.
11:11:00 AM: $ netlify-lambda install
11:11:00 AM: netlify-lambda: installing function dependencies
11:11:00 AM: Done in 53.59s.
11:11:00 AM: NPM modules installed using Yarn
11:11:01 AM: Started restoring cached go cache
11:11:01 AM: Finished restoring cached go cache
11:11:01 AM: Installing Go version 1.17 (requested 1.17)
11:11:05 AM: unset GOOS;
11:11:05 AM: unset GOARCH;
11:11:05 AM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
11:11:05 AM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
11:11:05 AM: go version >&2;
11:11:05 AM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
11:11:05 AM: go version go1.17 linux/amd64
11:11:05 AM: Installing missing commands
11:11:05 AM: Verify run directory
11:11:07 AM: ​
11:11:07 AM: ────────────────────────────────────────────────────────────────
11:11:07 AM:   Netlify Build                                                 
11:11:07 AM: ────────────────────────────────────────────────────────────────
11:11:07 AM: ​
11:11:07 AM: ❯ Version
11:11:07 AM:   @netlify/build 28.1.4
11:11:07 AM: ​
11:11:07 AM: ❯ Flags
11:11:07 AM:   apiHost: api.netlify.com
11:11:07 AM:   baseRelDir: true
11:11:07 AM:   branch: update/remove-plugin
11:11:07 AM:   buildId: 635c1ae6c223532571583c30
11:11:07 AM:   buildbotServerSocket: /tmp/netlify-buildbot-socket
11:11:07 AM:   cacheDir: /opt/build/cache
11:11:07 AM:   cachedConfigPath: /tmp/netlify_config.json
11:11:07 AM:   context: deploy-preview
11:11:07 AM:   cwd: /opt/build/repo
11:11:07 AM:   deployId: 635c1ae6c223532571583c32
11:11:07 AM:   edgeFunctionsDistDir: /tmp/edge-635c1ae6c223532571583c32
11:11:07 AM:   featureFlags:
11:11:07 AM:     - edge_functions_cache_cli
11:11:07 AM:     - edge_functions_produce_eszip
11:11:07 AM:     - edge_functions_system_logger
11:11:07 AM:   framework: gatsby
11:11:07 AM:   functionsDistDir: /tmp/zisi-635c1ae6c223532571583c32
11:11:07 AM:   mode: buildbot
11:11:07 AM:   nodePath: /opt/buildhome/.nvm/versions/node/v16.18.0/bin/node
11:11:07 AM:   repositoryRoot: /opt/build/repo
11:11:07 AM:   saveConfig: true
11:11:07 AM:   sendStatus: true
11:11:07 AM:   siteId: aaf32c69-2461-4a89-bdac-9d80666fa758
11:11:07 AM:   statsd:
11:11:07 AM:     host: 10.65.22.236
11:11:07 AM:     port: 8125
11:11:07 AM:   systemLogFile: 3
11:11:07 AM:   testOpts:
11:11:07 AM:     silentLingeringProcesses: ''
11:11:07 AM: ​
11:11:07 AM: ❯ Current directory
11:11:07 AM:   /opt/build/repo
11:11:07 AM: ​
11:11:07 AM: ❯ Config file
11:11:07 AM:   /opt/build/repo/netlify.toml
11:11:07 AM: ​
11:11:07 AM: ❯ Resolved config
11:11:07 AM:   build:
11:11:07 AM:     command: npm run build && npm run build-server
11:11:07 AM:     commandOrigin: config
11:11:07 AM:     environment:
11:11:07 AM:       - NETLIFY_BUILD_DEBUG
11:11:07 AM:       - NODE_ENV
11:11:07 AM:       - NODE_VERSION
11:11:07 AM:       - REVIEW_ID
11:11:07 AM:       - YARN_VERSION
11:11:07 AM:     publish: /opt/build/repo/public
11:11:07 AM:     publishOrigin: config
11:11:07 AM:   functionsDirectory: /opt/build/repo/lambda
11:11:07 AM: ❯ Context
11:11:07 AM:   deploy-preview
11:11:07 AM: ​
11:11:07 AM: ────────────────────────────────────────────────────────────────
11:11:07 AM:   1. build.command from netlify.toml                            
11:11:07 AM: ────────────────────────────────────────────────────────────────
11:11:07 AM: ​
11:11:07 AM: $ npm run build && npm run build-server
11:11:07 AM: > www-submittable-com@1.0.0 build
11:11:07 AM: > gatsby build
11:11:09 AM: success compile gatsby files - 0.835s
11:11:10 AM: success load gatsby config - 0.046s
11:11:10 AM: success load plugins - 0.671s
11:11:10 AM: warning gatsby-plugin-react-helmet: Gatsby now has built-in support for modifying the document head. Learn more at https://gatsby.dev/gatsby-head
11:11:10 AM: success onPreInit - 0.007s
11:11:10 AM: success initialize cache - 0.049s
11:11:10 AM: success copy gatsby files - 0.130s
11:11:11 AM: success Compiling Gatsby Functions - 0.169s
11:11:11 AM: success onPreBootstrap - 0.180s
11:11:11 AM: success createSchemaCustomization - 0.279s
11:11:13 AM: success Contentful: Sync all items - 1.601s - 3759/3759 2347.74/s
11:11:13 AM: success Contentful: Fetch data - 1.920s
11:11:13 AM: info Contentful: 830 new entries
11:11:13 AM: info Contentful: 1443 updated entries
11:11:13 AM: info Contentful: 0 deleted entries
11:11:13 AM: info Contentful: 0 cached entries
11:11:13 AM: info Contentful: 987 new assets
11:11:13 AM: info Contentful: 499 updated assets
11:11:13 AM: info Contentful: 0 cached assets
11:11:13 AM: info Contentful: 0 deleted assets
11:11:14 AM: info Creating 24 Contentful Cold Landing Page (Depreciated) nodes
11:11:14 AM: info Creating 45 Contentful Solutions Page nodes
11:11:14 AM: info Creating 52 Contentful Icons A nodes
11:11:15 AM: info Creating 130 Contentful Photo/Quote nodes
11:11:15 AM: info Creating 71 Contentful Screenshots nodes
11:11:16 AM: info Creating 19 Contentful Icons B nodes
11:11:16 AM: info Creating 156 Contentful Basic Image nodes
11:11:16 AM: info Creating 49 Contentful Six Items & Icons nodes
11:11:17 AM: info Creating 60 Contentful Solutions Cards Section nodes
11:11:18 AM: info Creating 188 Contentful FAQ Question nodes
11:11:18 AM: info Creating 213 Contentful Card nodes
11:11:19 AM: info Creating 25 Contentful Lists and List Pages nodes
11:11:19 AM: info Creating 68 Contentful Individual Webinar nodes
11:11:19 AM: info Creating 35 Contentful Customer Story nodes
11:11:19 AM: info Creating 52 Contentful Video nodes
11:11:19 AM: info Creating 1 Contentful Modal Popup and Announcement Bars nodes
11:11:19 AM: info Creating 90 Contentful Monthly/Annual Pricing Table Items nodes
11:11:19 AM: info Creating 2 Contentful Testimonial Sliders nodes
11:11:19 AM: info Creating 39 Contentful Feature Card nodes
11:11:19 AM: info Creating 55 Contentful CLPs nodes
11:11:19 AM: info Creating 320 Contentful Basic Rich Text nodes
11:11:19 AM: info Creating 10 Contentful Submittable 101 Lessons nodes
11:11:19 AM: info Creating 27 Contentful Menu nodes
11:11:19 AM: info Creating 7 Contentful Related Content By Use Case nodes
11:11:19 AM: info Creating 37 Contentful Logo Line or Statistics Line Component nodes
11:11:20 AM: info Creating 3 Contentful Video Series nodes
11:11:20 AM: info Creating 12 Contentful Any Content Page nodes
11:11:20 AM: info Creating 31 Contentful Form Field nodes
11:11:20 AM: info Creating 18 Contentful Form nodes
11:11:20 AM: info Creating 7 Contentful Tabbed Section nodes
11:11:20 AM: info Creating 23 Contentful Solutions Additional Features nodes
11:11:20 AM: info Creating 76 Contentful Pricing Table Items and Containers nodes
11:11:20 AM: info Creating 23 Contentful Impact Audio Episode nodes
11:11:20 AM: info Creating 79 Contentful Person, Guest, Host, or Team Member nodes
11:11:20 AM: info Creating 59 Contentful Menu Item nodes
11:11:20 AM: info Creating 6 Contentful Digital Guide Page nodes
11:11:20 AM: info Creating 18 Contentful Quote with Background Color nodes
11:11:20 AM: info Creating 98 Contentful Digital Guide Section nodes
11:11:20 AM: info Creating 1 Contentful Small Callout Block nodes
11:11:20 AM: info Creating 25 Contentful Microcopy nodes
11:11:20 AM: info Creating 3 Contentful Microcopy Group nodes
11:11:20 AM: info Creating 5 Contentful Announcement Bar nodes
11:11:20 AM: info Creating 1 Contentful Anchor Link nodes
11:11:20 AM: info Creating 5 Contentful Impact Studio Episode nodes
11:11:20 AM: info Creating 5 Contentful Basic Content Group nodes
11:11:20 AM: info Creating 1486 Contentful asset nodes
11:11:20 AM: success Contentful: Create nodes - 6.924s
11:11:20 AM: success Contentful: Process data - 7.100s
11:11:21 AM: ------------------- Fetching WordPress posts and populating WordPress data nodes -----------------------
11:11:21 AM: ------------------- Fetching Greenhouse job board -----------------------
11:11:21 AM: success Checking for changed pages - 0.000s
11:11:21 AM: success source and transform nodes - 9.674s
11:11:22 AM: info Writing GraphQL type definitions to /opt/build/repo/.cache/schema.gql
11:11:29 AM: success building schema - 7.930s
11:11:29 AM: ------------------- Creating thank you pages -----------------------
11:11:29 AM: ------------------- Creating customer stories pages -----------------------
11:11:29 AM: ------------------- Creating solutions pages -----------------------
11:11:29 AM: ------------------- Creating cold landing pages -----------------------
11:11:29 AM: ------------------- Creating CLP pages -----------------------
11:11:29 AM: ------------------- Creating CLP thank-you pages -----------------------
11:11:29 AM: ------------------- Creating webinar pages -----------------------
11:11:29 AM: ------------------- Creating terms pages -----------------------
11:11:29 AM: ------------------- Creating lessons pages -----------------------
11:11:29 AM: ------------------- Creating video series pages -----------------------
11:11:29 AM: ------------------- Creating digital guide pages -----------------------
11:11:29 AM: ------------------- Creating impact audio pages -----------------------
11:11:29 AM: ------------------- Creating FAQ pages -----------------------
11:11:29 AM: ------------------- Creating impact studio pages -----------------------
11:11:29 AM: did not create page for partners or covid-19-information; those are in pages
11:11:29 AM: didn't create webinar on demand or thank you page for webinar/grants-video-series/
didn't create webinar on demand or thank you page for webinar/higher-ed-video-series/
success createPages - 0.306s
11:11:29 AM: success createPagesStatefully - 0.199s
11:11:29 AM: info Total nodes: 8154, SitePage nodes: 537 (use --verbose for breakdown)
11:11:29 AM: success Checking for changed pages - 0.000s
11:11:29 AM: success onPreExtractQueries - 0.000s
11:11:51 AM: success extract queries from components - 21.571s
11:11:51 AM: success write out redirect data - 0.002s
11:11:51 AM: warning The icon(src/images/icon.png) you provided to 'gatsby-plugin-manifest' is not square.
11:11:51 AM: The icons we generate will be square and for the best results we recommend you provide a square icon.
11:11:53 AM: success Build manifest and related icons - 1.992s
11:11:53 AM: success onPostBootstrap - 1.993s
11:11:53 AM: info bootstrap finished - 45.935s
11:11:53 AM: success write out requires - 0.011s
11:12:53 AM: Killed
11:12:53 AM: ​
11:12:53 AM: ────────────────────────────────────────────────────────────────
11:12:53 AM:   "build.command" failed                                        
11:12:53 AM: ────────────────────────────────────────────────────────────────
11:12:53 AM: ​
11:12:53 AM:   Error message
11:12:53 AM:   Command failed with exit code 137: npm run build && npm run build-server (https://ntl.fyi/exit-code-137)
11:12:53 AM: ​
11:12:53 AM:   Error location
11:12:53 AM:   In build.command from netlify.toml:
11:12:53 AM:   npm run build && npm run build-server
11:12:53 AM: ​
11:12:53 AM:   Resolved config
11:12:53 AM:   build:
11:12:53 AM:     command: npm run build && npm run build-server
11:12:53 AM:     commandOrigin: config
11:12:53 AM:     environment:
11:12:53 AM:       - NETLIFY_BUILD_DEBUG
11:12:53 AM:       - NODE_ENV
11:12:53 AM:       - NODE_VERSION
11:12:53 AM:       - REVIEW_ID
11:12:53 AM:       - YARN_VERSION
11:12:53 AM:     publish: /opt/build/repo/public
11:12:53 AM:     publishOrigin: config
11:12:53 AM:   functionsDirectory: /opt/build/repo/lambda
1:12:53 AM: Caching artifacts
11:12:53 AM: Started saving node modules
11:12:53 AM: Finished saving node modules
11:12:53 AM: Started saving build plugins
11:12:53 AM: Finished saving build plugins
11:12:53 AM: Started saving yarn cache
11:13:39 AM: Finished saving yarn cache
11:13:39 AM: Started saving pip cache
11:13:39 AM: Finished saving pip cache
11:13:39 AM: Started saving emacs cask dependencies
11:13:39 AM: Finished saving emacs cask dependencies
11:13:39 AM: Started saving maven dependencies
11:13:39 AM: Finished saving maven dependencies
11:13:39 AM: Started saving boot dependencies
11:13:39 AM: Finished saving boot dependencies
11:13:39 AM: Started saving rust rustup cache
11:13:39 AM: Finished saving rust rustup cache
11:13:39 AM: Started saving go dependencies
11:13:39 AM: Finished saving go dependencies
11:13:41 AM: Cached ruby version 2.7.1
11:13:41 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:13:41 AM: Creating deploy upload records
11:13:42 AM: Failing build: Failed to build site
11:13:42 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
11:13:42 AM: Finished processing build request in 3m53.290654364s

This is the problem.

Your build went over the 11 GiB RAM limit:

Hi @hrishikesh thanks for your response. That provided the missing piece I was having trouble confirming. I did try some build optimization but was still running into issues.

After some digging I believe my issues is possibly related to PQR (Parallel Query Running) as you suggested in this thread: Gatsby v4 Builds suddenly killed, exit code 137 - #6 by hrishikesh as I also updated to Gatsby 4 recently.

Trying the flag GATSBY_CPU_COUNT as was suggested in this: Gatsby v4 memory usage during Parallel Query Running · Discussion #34215 · gatsbyjs/gatsby · GitHub looks like it resulted in a successful build so I think at this point any additional troubleshooting I do is going to be PQR related. Thanks for your help again!

Thanks so much for coming back and sharing these details-- so glad you are unblocked! Happy building :smile: