Build.command failed, exit code 137 with seemingly no error message

My site name is beautiful-cucurucho-1010c2

The build keeps stopping with the message Killed and then “build.command” failed but no other error messages that indicate what’s happening. The exit code provided is 137, I’ve tried reading the other threads about this error code but they either don’t provide a solution or the build is failing because of some other error.

10:24:07 AM: Build ready to start
10:24:10 AM: build-image version: d7b3dbfb0846505993c9a131894d1858074c90b4 (focal)
10:24:10 AM: build-image tag: v4.10.1
10:24:10 AM: buildbot version: 1c362ef848ac5e35535bdb572ebca893db28c8a0
10:24:10 AM: Fetching cached dependencies
10:24:10 AM: Failed to fetch cache, continuing with build
10:24:10 AM: Starting to prepare the repo for build
10:24:10 AM: No cached dependencies found. Cloning fresh repo
10:24:10 AM: git clone https://github.com/Fourbn/this-inescapable-city
10:25:31 AM: Preparing Git Reference refs/heads/main
10:25:45 AM: Parsing package.json dependencies
10:25:46 AM: Starting build script
10:25:46 AM: Installing dependencies
10:25:46 AM: Python version set to 2.7
10:25:47 AM: Downloading and installing node v16.17.0...
10:25:47 AM: Downloading https://nodejs.org/dist/v16.17.0/node-v16.17.0-linux-x64.tar.xz...
10:25:47 AM: Computing checksum with sha256sum
10:25:47 AM: Checksums matched!
10:25:49 AM: Now using node v16.17.0 (npm v8.15.0)
10:25:49 AM: Started restoring cached build plugins
10:25:49 AM: Finished restoring cached build plugins
10:25:49 AM: Attempting ruby version 2.7.2, read from environment
10:25:50 AM: Using ruby version 2.7.2
10:25:50 AM: Using PHP version 8.0
10:25:50 AM: No npm workspaces detected
10:25:50 AM: Started restoring cached node modules
10:25:50 AM: Finished restoring cached node modules
10:25:51 AM: Installing NPM modules using NPM version 8.15.0
10:25:51 AM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
10:25:51 AM: npm WARN config location in the cache, and they are managed by
10:25:51 AM: npm WARN config     [`cacache`](http://npm.im/cacache).
10:25:51 AM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
10:25:51 AM: npm WARN config location in the cache, and they are managed by
10:25:51 AM: npm WARN config     [`cacache`](http://npm.im/cacache).
10:25:57 AM: npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
10:25:57 AM: npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
10:25:58 AM: npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
10:25:58 AM: npm WARN deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
10:25:59 AM: npm WARN deprecated querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
10:25:59 AM: npm WARN deprecated multer@1.4.4: Multer 1.x is affected by CVE-2022-24434. This is fixed in v1.4.4-lts.1 which drops support for versions of Node.js before 6. Please upgrade to at least Node.js 6 and version 1.4.4-lts.1 of Multer. If you need support for older versions of Node.js, we are open to accepting patches that would fix the CVE on the main 1.x release line, whilst maintaining compatibility with Node.js 0.10.
10:26:00 AM: npm WARN deprecated subscriptions-transport-ws@0.9.19: The `subscriptions-transport-ws` package is no longer maintained. We recommend you use `graphql-ws` instead. For help migrating Apollo software to `graphql-ws`, see https://www.apollographql.com/docs/apollo-server/data/subscriptions/#switching-from-subscriptions-transport-ws    For general help using `graphql-ws`, see https://github.com/enisdenjo/graphql-ws/blob/master/README.md
10:26:01 AM: npm WARN deprecated async-cache@1.1.0: No longer maintained. Use [lru-cache](http://npm.im/lru-cache) version 7.6 or higher, and provide an asynchronous `fetchMethod` option.
10:26:03 AM: npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
10:26:03 AM: npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
10:26:03 AM: npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
10:26:04 AM: npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
10:26:04 AM: npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
10:26:05 AM: npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
10:26:05 AM: npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
10:26:05 AM: npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
10:26:06 AM: npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
10:26:25 AM: added 1604 packages, and audited 1605 packages in 34s
10:26:25 AM: 223 packages are looking for funding
10:26:25 AM:   run `npm fund` for details
10:26:25 AM: 27 vulnerabilities (13 moderate, 13 high, 1 critical)
10:26:25 AM: To address issues that do not require attention, run:
10:26:25 AM:   npm audit fix
10:26:25 AM: To address all issues (including breaking changes), run:
10:26:25 AM:   npm audit fix --force
10:26:25 AM: Run `npm audit` for details.
10:26:25 AM: NPM modules installed
10:26:25 AM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
10:26:25 AM: npm WARN config location in the cache, and they are managed by
10:26:25 AM: npm WARN config     [`cacache`](http://npm.im/cacache).
10:26:25 AM: Started restoring cached go cache
10:26:25 AM: Finished restoring cached go cache
10:26:25 AM: Installing Go version 1.17 (requested 1.17)
10:26:30 AM: unset GOOS;
10:26:30 AM: unset GOARCH;
10:26:30 AM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
10:26:30 AM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
10:26:30 AM: go version >&2;
10:26:30 AM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
10:26:30 AM: go version go1.17 linux/amd64
10:26:30 AM: Installing missing commands
10:26:30 AM: Verify run directory
10:26:31 AM: ​
10:26:31 AM: ────────────────────────────────────────────────────────────────
10:26:31 AM:   Netlify Build                                                 
10:26:31 AM: ────────────────────────────────────────────────────────────────
10:26:31 AM: ​
10:26:31 AM: ❯ Version
10:26:31 AM:   @netlify/build 27.18.4
10:26:31 AM: ​
10:26:31 AM: ❯ Flags
10:26:31 AM:   baseRelDir: true
10:26:31 AM:   buildId: 632dc1871e602c0009bfffe3
10:26:31 AM:   deployId: 632dc1871e602c0009bfffe5
10:26:31 AM: ​
10:26:31 AM: ❯ Current directory
10:26:31 AM:   /opt/build/repo
10:26:31 AM: ​
10:26:31 AM: ❯ Config file
10:26:31 AM:   No config file was defined: using default values.
10:26:31 AM: ​
10:26:31 AM: ❯ Context
10:26:31 AM:   production
10:26:32 AM: ​
10:26:32 AM: ❯ Installing plugins
10:26:32 AM:    - @netlify/plugin-gatsby@3.4.7
10:26:40 AM: ​
10:26:40 AM: ❯ Loading plugins
10:26:40 AM:    - @netlify/plugin-gatsby@3.4.7 from Netlify app
10:26:41 AM: ​
10:26:41 AM: ────────────────────────────────────────────────────────────────
10:26:41 AM:   1. @netlify/plugin-gatsby (onPreBuild event)                  
10:26:41 AM: ────────────────────────────────────────────────────────────────
10:26:41 AM: ​
10:26:41 AM: No Gatsby cache found. Building fresh.
10:26:41 AM: ​
10:26:41 AM: (@netlify/plugin-gatsby onPreBuild completed in 11ms)
10:26:41 AM: ​
10:26:41 AM: ────────────────────────────────────────────────────────────────
10:26:41 AM:   2. Build command from Netlify app                             
10:26:41 AM: ────────────────────────────────────────────────────────────────
10:26:41 AM: ​
10:26:41 AM: $ npm run build
10:26:41 AM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
10:26:41 AM: npm WARN config location in the cache, and they are managed by
10:26:41 AM: npm WARN config     [`cacache`](http://npm.im/cacache).
10:26:41 AM: > inescapable-city@1.0.0 build
10:26:41 AM: > gatsby build
10:26:44 AM: success compile gatsby files - 0.807s
10:26:44 AM: success load gatsby config - 0.023s
10:26:44 AM: success load plugins - 0.518s
10:26:44 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
10:26:44 AM: success onPreInit - 0.006s
10:26:44 AM: success initialize cache - 0.052s
10:26:44 AM: success copy gatsby files - 0.135s
10:26:45 AM: success Compiling Gatsby Functions - 0.135s
10:26:45 AM: success onPreBootstrap - 0.220s
10:26:45 AM: success createSchemaCustomization - 0.203s
10:26:46 AM: success Contentful: Sync all items - 0.186s - 48/48 258.18/s
10:26:46 AM: success Contentful: Fetch data - 0.601s
10:26:46 AM: info Contentful: 7 new entries
10:26:46 AM: info Contentful: 2 updated entries
10:26:46 AM: info Contentful: 0 deleted entries
10:26:46 AM: info Contentful: 0 cached entries
10:26:46 AM: info Contentful: 36 new assets
10:26:46 AM: info Contentful: 3 updated assets
10:26:46 AM: info Contentful: 0 cached assets
10:26:46 AM: info Contentful: 0 deleted assets
10:26:46 AM: info Creating 9 Contentful Artist Page nodes
10:26:46 AM: info Creating 39 Contentful asset nodes
10:26:46 AM: success Contentful: Create nodes - 0.306s
10:26:46 AM: success Contentful: Process data - 0.310s
10:27:02 AM: success Checking for changed pages - 0.000s
10:27:02 AM: success source and transform nodes - 16.777s
10:27:02 AM: info Writing GraphQL type definitions to /opt/build/repo/.cache/schema.gql
10:27:02 AM: success building schema - 0.234s
10:27:02 AM: success createPages - 0.002s
10:27:02 AM: success createPagesStatefully - 0.091s
10:27:02 AM: info Total nodes: 127, SitePage nodes: 17 (use --verbose for breakdown)
10:27:02 AM: success Checking for changed pages - 0.000s
10:27:02 AM: success onPreExtractQueries - 0.001s
10:27:05 AM: success extract queries from components - 2.858s
10:27:05 AM: success write out redirect data - 0.004s
10:27:05 AM: success onPostBootstrap - 0.000s
10:27:05 AM: info bootstrap finished - 23.717s
10:27:05 AM: success write out requires - 0.002s
10:27:53 AM: success Building production JavaScript and CSS bundles - 47.668s
10:28:08 AM: Killed
10:28:08 AM: ​
10:28:08 AM: ────────────────────────────────────────────────────────────────
10:28:08 AM:   "build.command" failed                                        
10:28:08 AM: ────────────────────────────────────────────────────────────────
10:28:08 AM: ​
10:28:08 AM:   Error message
10:28:08 AM:   Command failed with exit code 137: npm run build (https://ntl.fyi/exit-code-137)
10:28:08 AM: ​
10:28:08 AM:   Error location
10:28:08 AM:   In Build command from Netlify app:
10:28:08 AM:   npm run build
10:28:08 AM: ​
10:28:08 AM:   Resolved config
10:28:08 AM:   build:
10:28:08 AM:     command: npm run build
10:28:08 AM:     commandOrigin: ui
10:28:08 AM:     environment:
10:28:08 AM:       - GATSBY_ACCESS_TOKEN
10:28:08 AM:       - GATSBY_SPACE_ID
10:28:08 AM:     publish: /opt/build/repo/public
10:28:08 AM:     publishOrigin: ui
10:28:08 AM:   plugins:
10:28:08 AM:     - inputs: {}
10:28:08 AM:       origin: ui
10:28:08 AM:       package: '@netlify/plugin-gatsby'
10:28:09 AM: Caching artifacts
10:28:09 AM: Started saving node modules
10:28:09 AM: Finished saving node modules
10:28:09 AM: Started saving build plugins
10:28:09 AM: Finished saving build plugins
10:28:09 AM: Started saving pip cache
10:28:09 AM: Finished saving pip cache
10:28:09 AM: Started saving emacs cask dependencies
10:28:09 AM: Finished saving emacs cask dependencies
10:28:09 AM: Started saving maven dependencies
10:28:09 AM: Finished saving maven dependencies
10:28:09 AM: Started saving boot dependencies
10:28:09 AM: Finished saving boot dependencies
10:28:09 AM: Started saving rust rustup cache
10:28:09 AM: Finished saving rust rustup cache
10:28:09 AM: Started saving go dependencies
10:28:09 AM: Finished saving go dependencies
10:28:13 AM: Creating deploy upload records
10:28:13 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
10:28:14 AM: Failing build: Failed to build site
10:28:14 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
10:28:14 AM: Finished processing build request in 4m4.195024325s

I’ve run this build a few times. For a few builds it was hitting a legitimate error that I resolved but also, intermittently, it would just get Killed and stop building randomly. Usually always around this “write out requires” or “building production JS and CSS bundles” phase. I’m in the process of running a Docker image but figured I’d also post here while setting that up.

I read that this may be a memory issue, but I would love some clarification about what that is or any ideas on what I am missing here. I’ve built many many Gatsby sites using Netlify and never encountered this before so I am a bit stumped.

Thanks for your help!

Each site needs a different amount of system resources. Chances are the ones that were successful did not need high limits, but this one does. We can’t say much about your site’s requirements, but it would be the best way for you to try using Netlify Docker image locally to see how much memory your site needs to build successfully and try to optimise that.