Gatsby build error from Git

The following error when trying to do a build from Git to Netlify. (NB I can build this fine locally and have the public folder loaded fine to Netlify but it won’t build from GIT).

I looked through the forum but couldn’t find much on the “Error: std::bad_alloc” that matched my setup.

My site

The error messages…

9:37:20 AM: There is no log for this deploy
9:37:54 AM: Build ready to start
9:37:56 AM: build-image version: d2c6dbeac570350a387d832f64bc980dc964ad65 (focal)
9:37:56 AM: build-image tag: v4.8.0
9:37:56 AM: buildbot version: d7330f24833f29d0263d28116347ab83094a2561
9:37:56 AM: Fetching cached dependencies
9:37:56 AM: Failed to fetch cache, continuing with build
9:37:56 AM: Starting to prepare the repo for build
9:37:56 AM: No cached dependencies found. Cloning fresh repo
9:37:56 AM: git clone GitHub - blackbeak/Gatsby_netifly
9:38:10 AM: Preparing Git Reference refs/heads/main
9:38:10 AM: Parsing package.json dependencies
9:38:11 AM: Starting build script
9:38:11 AM: Installing dependencies
9:38:11 AM: Python version set to 2.7
9:38:12 AM: Downloading and installing node v16.15.1…
9:38:12 AM: Downloading https://nodejs.org/dist/v16.15.1/node-v16.15.1-linux-x64.tar.xz
9:38:13 AM: Computing checksum with sha256sum
9:38:13 AM: Checksums matched!
9:38:15 AM: Now using node v16.15.1 (npm v8.11.0)
9:38:15 AM: Started restoring cached build plugins
9:38:15 AM: Finished restoring cached build plugins
9:38:15 AM: Attempting ruby version 2.7.2, read from environment
9:38:16 AM: Using ruby version 2.7.2
9:38:16 AM: Using PHP version 8.0
9:38:16 AM: Started restoring cached yarn cache
9:38:16 AM: Finished restoring cached yarn cache
9:38:17 AM: No yarn workspaces detected
9:38:17 AM: Started restoring cached node modules
9:38:18 AM: Finished restoring cached node modules
9:38:18 AM: Installing NPM modules using Yarn version 1.22.10
9:38:18 AM: npm WARN config tmp This setting is no longer used. npm stores temporary files in a special
9:38:18 AM: npm WARN config location in the cache, and they are managed by
9:38:18 AM: npm WARN config cacache.
9:38:18 AM: yarn install v1.22.10
9:38:18 AM: [1/4] Resolving packages…
9:38:19 AM: [2/4] Fetching packages…
9:38:39 AM: info fsevents@2.3.2: The platform “linux” is incompatible with this module.
9:38:39 AM: info “fsevents@2.3.2” is an optional dependency and failed compatibility check. Excluding it from installation.
9:38:39 AM: info lmdb-darwin-arm64@2.3.10: The platform “linux” is incompatible with this module.
9:38:39 AM: info “lmdb-darwin-arm64@2.3.10” is an optional dependency and failed compatibility check. Excluding it from installation.
9:38:39 AM: info lmdb-darwin-arm64@2.3.10: The CPU architecture “x64” is incompatible with this module.
9:38:39 AM: info lmdb-darwin-x64@2.3.10: The platform “linux” is incompatible with this module.
9:38:39 AM: info “lmdb-darwin-x64@2.3.10” is an optional dependency and failed compatibility check. Excluding it from installation.
9:38:39 AM: info lmdb-linux-arm@2.3.10: The CPU architecture “x64” is incompatible with this module.
9:38:39 AM: info “lmdb-linux-arm@2.3.10” is an optional dependency and failed compatibility check. Excluding it from installation.
9:38:39 AM: info lmdb-linux-arm64@2.3.10: The CPU architecture “x64” is incompatible with this module.
9:38:39 AM: info “lmdb-linux-arm64@2.3.10” is an optional dependency and failed compatibility check. Excluding it from installation.
9:38:39 AM: info lmdb-win32-x64@2.3.10: The platform “linux” is incompatible with this module.
9:38:39 AM: info “lmdb-win32-x64@2.3.10” is an optional dependency and failed compatibility check. Excluding it from installation.
9:38:39 AM: info @msgpackr-extract/msgpackr-extract-darwin-arm64@2.0.2: The platform “linux” is incompatible with this module.
9:38:39 AM: info “@msgpackr-extract/msgpackr-extract-darwin-arm64@2.0.2” is an optional dependency and failed compatibility check. Excluding it from installation.
9:38:39 AM: info @msgpackr-extract/msgpackr-extract-darwin-arm64@2.0.2: The CPU architecture “x64” is incompatible with this module.
9:38:39 AM: info @msgpackr-extract/msgpackr-extract-darwin-x64@2.0.2: The platform “linux” is incompatible with this module.
9:38:39 AM: info “@msgpackr-extract/msgpackr-extract-darwin-x64@2.0.2” is an optional dependency and failed compatibility check. Excluding it from installation.
9:38:39 AM: info @msgpackr-extract/msgpackr-extract-linux-arm@2.0.2: The CPU architecture “x64” is incompatible with this module.
9:38:39 AM: info “@msgpackr-extract/msgpackr-extract-linux-arm@2.0.2” is an optional dependency and failed compatibility check. Excluding it from installation.
9:38:39 AM: info @msgpackr-extract/msgpackr-extract-linux-arm64@2.0.2: The CPU architecture “x64” is incompatible with this module.
9:38:39 AM: info “@msgpackr-extract/msgpackr-extract-linux-arm64@2.0.2” is an optional dependency and failed compatibility check. Excluding it from installation.
9:38:39 AM: info @msgpackr-extract/msgpackr-extract-win32-x64@2.0.2: The platform “linux” is incompatible with this module.
9:38:39 AM: info “@msgpackr-extract/msgpackr-extract-win32-x64@2.0.2” is an optional dependency and failed compatibility check. Excluding it from installation.
9:38:39 AM: [3/4] Linking dependencies…
9:38:39 AM: warning “gatsby > eslint-config-react-app@6.0.0” has unmet peer dependency “babel-eslint@^10.0.0”.
9:38:39 AM: warning “gatsby > @typescript-eslint/eslint-plugin > tsutils@3.21.0” has unmet peer dependency “typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta”.
9:38:39 AM: warning “gatsby > gatsby-parcel-config > @gatsbyjs/parcel-namer-relative-to-cwd@1.1.0” has incorrect peer dependency “@parcel/namer-default@2.5.0”.
9:38:39 AM: warning “gatsby > react-dev-utils > fork-ts-checker-webpack-plugin@6.5.2” has unmet peer dependency “typescript@>= 2.7”.
9:38:39 AM: warning “gatsby > eslint-plugin-graphql > graphql-config > @endemolshinegroup/cosmiconfig-typescript-loader > ts-node@9.1.1” has unmet peer dependency “typescript@>=2.7”.
9:38:39 AM: warning " > gatsby-plugin-gatsby-cloud@4.16.0" has unmet peer dependency “webpack@*”.
9:38:39 AM: warning “gatsby-plugin-gatsby-cloud > webpack-assets-manifest@5.1.0” has unmet peer dependency “webpack@^5.2.0”.
9:38:39 AM: warning " > gatsby-plugin-image@2.16.1" has unmet peer dependency “@babel/core@^7.12.3”.
9:38:39 AM: warning " > gatsby-plugin-image@2.16.1" has unmet peer dependency “gatsby-source-filesystem@^4.0.0-next”.
9:38:39 AM: warning “gatsby-plugin-postcss > postcss-loader@4.3.0” has unmet peer dependency “webpack@^4.0.0 || ^5.0.0”.
9:38:39 AM: warning " > gatsby-source-strapi@2.0.0" has unmet peer dependency “sharp@^0.29.0”.
9:38:39 AM: warning " > slick-carousel@1.8.1" has unmet peer dependency “jquery@>=1.8.0”.
9:38:39 AM: warning “eslint-config-react-app > eslint-plugin-flowtype@8.0.3” has unmet peer dependency “@babel/plugin-syntax-flow@^7.14.5”.
9:38:39 AM: warning “eslint-config-react-app > eslint-plugin-flowtype@8.0.3” has unmet peer dependency “@babel/plugin-transform-react-jsx@^7.14.9”.
9:38:39 AM: warning Workspaces can only be enabled in private projects.
9:38:51 AM: [4/4] Building fresh packages…
9:38:56 AM: Done in 37.62s.
9:38:56 AM: NPM modules installed using Yarn
9:38:56 AM: Started restoring cached go cache
9:38:56 AM: Finished restoring cached go cache
9:38:56 AM: Installing Go version 1.17
9:39:01 AM: unset GOOS;
9:39:01 AM: unset GOARCH;
9:39:01 AM: export GOROOT=‘/opt/buildhome/.gimme_cache/versions/go1.17.linux.amd64’;
9:39:01 AM: export PATH=“/opt/buildhome/.gimme_cache/versions/go1.17.linux.amd64/bin:${PATH}”;
9:39:01 AM: go version >&2;
9:39:01 AM: export GIMME_ENV=“/opt/buildhome/.gimme_cache/env/go1.17.linux.amd64.env”
9:39:01 AM: go version go1.17 linux/amd64
9:39:01 AM: Installing missing commands
9:39:01 AM: Verify run directory
9:39:02 AM: ​
9:39:02 AM: ────────────────────────────────────────────────────────────────
9:39:02 AM: Netlify Build
9:39:02 AM: ────────────────────────────────────────────────────────────────
9:39:02 AM: ​
9:39:02 AM: ❯ Version
9:39:02 AM: @netlify/build 27.1.3
9:39:02 AM: ​
9:39:02 AM: ❯ Flags
9:39:02 AM: baseRelDir: true
9:39:02 AM: buildId: 62a2e6554680f8000835ca5b
9:39:02 AM: deployId: 62a2e6554680f8000835ca5d
9:39:02 AM: ​
9:39:02 AM: ❯ Current directory
9:39:02 AM: /opt/build/repo
9:39:02 AM: ​
9:39:02 AM: ❯ Config file
9:39:02 AM: No config file was defined: using default values.
9:39:02 AM: ​
9:39:02 AM: ❯ Context
9:39:02 AM: production
9:39:02 AM: ​
9:39:02 AM: ❯ Installing plugins
9:39:02 AM: - @netlify/plugin-gatsby@3.2.1
9:39:14 AM: ​
9:39:14 AM: ❯ Loading plugins
9:39:14 AM: - @netlify/plugin-gatsby@3.2.1 from Netlify app
9:39:15 AM: ​
9:39:15 AM: ────────────────────────────────────────────────────────────────
9:39:15 AM: 1. @netlify/plugin-gatsby (onPreBuild event)
9:39:15 AM: ────────────────────────────────────────────────────────────────
9:39:15 AM: ​
9:39:15 AM: No Gatsby cache found. Building fresh.
9:39:15 AM: ​
9:39:15 AM: (@netlify/plugin-gatsby onPreBuild completed in 15ms)
9:39:15 AM: ​
9:39:15 AM: ────────────────────────────────────────────────────────────────
9:39:15 AM: 2. Build command from Netlify app
9:39:15 AM: ────────────────────────────────────────────────────────────────
9:39:15 AM: ​
9:39:15 AM: $ yarn build
9:39:15 AM: yarn run v1.22.10
9:39:15 AM: $ gatsby build
9:39:17 AM: error There was an unhandled error during compilation for /opt/build/repo. Please run the command with the --verbose flag again.
9:39:17 AM: std::bad_alloc
9:39:17 AM:
9:39:17 AM:
9:39:17 AM: Error: std::bad_alloc
9:39:17 AM:
9:39:17 AM: not finished compile gatsby files - 0.098s
9:39:17 AM: error Command failed with exit code 1. (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
9:39:17 AM: info Visit yarn run | Yarn for documentation about this command.
9:39:17 AM: ​
9:39:17 AM: ────────────────────────────────────────────────────────────────
9:39:17 AM: “build.command” failed
9:39:17 AM: ────────────────────────────────────────────────────────────────
9:39:17 AM: ​
9:39:17 AM: Error message
9:39:17 AM: Command failed with exit code 1: yarn build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
9:39:17 AM: ​
9:39:17 AM: Error location
9:39:17 AM: In Build command from Netlify app:
9:39:17 AM: yarn build
9:39:17 AM: ​
9:39:17 AM: Resolved config
9:39:17 AM: build:
9:39:17 AM: command: yarn build
9:39:17 AM: commandOrigin: ui
9:39:17 AM: publish: /opt/build/repo/public
9:39:17 AM: publishOrigin: ui
9:39:17 AM: plugins:
9:39:17 AM: - inputs: {}
9:39:17 AM: origin: ui
9:39:17 AM: package: ‘@netlify/plugin-gatsby’
9:39:18 AM: Caching artifacts
9:39:18 AM: Started saving node modules
9:39:18 AM: Finished saving node modules
9:39:18 AM: Started saving build plugins
9:39:18 AM: Finished saving build plugins
9:39:18 AM: Started saving yarn cache
9:39:23 AM: Finished saving yarn cache
9:39:23 AM: Started saving pip cache
9:39:23 AM: Finished saving pip cache
9:39:23 AM: Started saving emacs cask dependencies
9:39:23 AM: Finished saving emacs cask dependencies
9:39:23 AM: Started saving maven dependencies
9:39:23 AM: Finished saving maven dependencies
9:39:23 AM: Started saving boot dependencies
9:39:23 AM: Finished saving boot dependencies
9:39:23 AM: Started saving rust rustup cache
9:39:23 AM: Finished saving rust rustup cache
9:39:23 AM: Started saving go dependencies
9:39:24 AM: Finished saving go dependencies
9:39:25 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:39:25 AM: Creating deploy upload records
9:39:25 AM: Failing build: Failed to build site
9:39:25 AM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
9:39:26 AM: Finished processing build request in 1m29.89656479s

hi there, could you show us your package.json please?

Hi Perry

This is it.
{
“name”: “my-gatsby-blog”,
“version”: “1.0.5”,
“private”: true,
“description”: “Strapi Gatsby Blog”,
“author”: “Strapi team”,
“keywords”: [
“gatsby”
],
“scripts”: {
“develop”: “gatsby develop”,
“start”: “gatsby develop”,
“build”: “gatsby build”,
“serve”: “gatsby serve”,
“clean”: “gatsby clean”,
“lint”: “eslint .”,
“lint:fix”: “eslint . --fix”
},
“dependencies”: {
“gatsby”: “^4.6.1”,
“gatsby-plugin-gatsby-cloud”: “^4.7.0”,
“gatsby-plugin-image”: “^2.6.0”,
“gatsby-plugin-netlify”: “^5.0.0”,
“gatsby-plugin-postcss”: “^5.6.0”,
“gatsby-plugin-sharp”: “^4.6.0”,
“gatsby-source-strapi”: “^2.0.0”,
“gatsby-transformer-remark”: “^5.6.0”,
“gatsby-transformer-sharp”: “^4.6.0”,
“postcss”: “^8.4.6”,
“react”: “^17.0.1”,
“react-dom”: “^17.0.1”,
“react-helmet”: “^6.1.0”,
“react-slick”: “^0.28.1”,
“slick-carousel”: “^1.8.1”
},
“devDependencies”: {
@tailwindcss/line-clamp”: “^0.3.1”,
@tailwindcss/typography”: “^0.5.1”,
“autoprefixer”: “^10.4.2”,
“eslint”: “^8.8.0”,
“eslint-config-prettier”: “^8.3.0”,
“eslint-config-react-app”: “^7.0.0”,
“eslint-plugin-prettier”: “^4.0.0”,
“prettier”: “^2.5.1”,
“prettier-plugin-tailwindcss”: “^0.1.4”,
“tailwindcss”: “^3.0.18”
}
}

Spent all day trying to de-bug this. It works fine on localhost and when I copy the generated public file it deploys. I got a webhook working with Strapi on Heroku too and it’s creating a build. So it’s close to what I want. But its not finishing the build.
Anything you can point me too would be most helpful.

Hey @stevej,

The problem is because your build is running out of memory:

You can read more about it here:

Thanks for letting me know. This is a relatively light simple site. How do I reduce the memory being used?

Unfortunately, we can’t comment much on that. I’ve linked the guide above about “general guidelines”, but any specific guidelines would be specific for your codebase. Could be some dependencies, or inefficient use of tools, etc.

Still not able to reduce the memory issue. This is a straight build from Gatsby blog sample on strapi CMS. I am not sure how to reduce the memory and install the system.

While we don’t have specific instructions or guidance to provide which would help you reduce memory usage for your specific site, we did do a bit of searching to see and found the following articles which should help you get started investigating the memory usage so you can optimize it:

If you are running our build image locally ( instructions found on GitHub here ), I would recommend looking through this article about Docker runtime metrics: Runtime metrics | Docker Documentation

This is some general advice on troubleshooting Node memory usage, and since your build seems to use Node, this might be beneficial for you as well: Optimize Node.js memory consumption - Stack Overflow

Please have a look and let us know if that helps or if you have any additional questions.