Deployment success/failure is a hit or miss

Netlify site name: gatographql.com
Stack: Next.js

Deploying my site often fails, and sometimes succeeds, without meaningful changes to the code. For instance sometimes it fails, then I do “Retry”, and it works.

I wonder what I can do to achieve a consistent behavior, so that it always succeeds.

(Notice that I’m Netlify’s free plan, which I believe should be enough to cover the site’s requirements)

The failed deployments happen due to memory issues, as I get error message “Command failed with exit code 137: npm run build (Search results for '"non-zero exit code: 137"' - Netlify Support Forums)”:

2:15:18 PM: Netlify Build                                                 
2:15:18 PM: ────────────────────────────────────────────────────────────────
2:15:18 PM: ​
2:15:18 PM: ❯ Version
2:15:18 PM:   @netlify/build 29.36.3
2:15:18 PM: ​
2:15:18 PM: ❯ Flags
2:15:18 PM:   baseRelDir: true
2:15:18 PM:   buildId: 65f1444490c57b9a6a7964b6
2:15:18 PM:   deployId: 65f1444490c57b9a6a7964b8
2:15:18 PM: ​
2:15:18 PM: ❯ Current directory
2:15:18 PM:   /opt/build/repo
2:15:18 PM: ​
2:15:18 PM: ❯ Config file
2:15:18 PM:   /opt/build/repo/netlify.toml
2:15:18 PM: ​
2:15:18 PM: ❯ Context
2:15:18 PM:   production
2:15:18 PM: ​
2:15:18 PM: ❯ Installing plugins
2:15:18 PM:    - @netlify/plugin-nextjs@5.0.0-rc.4
2:15:19 PM: ​
2:15:19 PM: ❯ Using Next.js Runtime - v5.0.0-rc.4
2:15:20 PM: ​
2:15:20 PM: @netlify/plugin-nextjs (onPreBuild event)                     
2:15:20 PM: ────────────────────────────────────────────────────────────────
2:15:20 PM: ​
2:15:20 PM: No Next.js cache to restore
2:15:20 PM: ​
2:15:20 PM: (@netlify/plugin-nextjs onPreBuild completed in 8ms)
2:15:20 PM: ​
2:15:20 PM: build.command from netlify.toml                               
2:15:20 PM: ────────────────────────────────────────────────────────────────
2:15:20 PM: ​
2:15:20 PM: $ npm run build
2:15:20 PM: > stellar-next@0.1.0 build
2:15:20 PM: > NODE_OPTIONS=--max-old-space-size=8192 next build
2:15:21 PM: ⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
2:15:21 PM:    ▲ Next.js 14.0.3
2:15:21 PM:    Creating an optimized production build ...
2:15:34 PM: Generated 356 documents in .contentlayer
2:15:49 PM:  ✓ Compiled successfully
2:15:49 PM:    Linting and checking validity of types ...
2:15:55 PM:    Collecting page data ...
2:16:04 PM:    Generating static pages (0/241) ...
2:16:07 PM:    Generating static pages (60/241)
2:16:07 PM:    Generating static pages (120/241)
2:16:11 PM: Killed
2:16:11 PM: ​
2:16:11 PM: @netlify/plugin-nextjs (onEnd event)                          
2:16:11 PM: ────────────────────────────────────────────────────────────────
2:16:11 PM: ​
2:16:11 PM: ​
2:16:11 PM: (@netlify/plugin-nextjs onEnd completed in 187ms)
2:16:11 PM: ​
2:16:11 PM: "build.command" failed                                        
2:16:11 PM: ────────────────────────────────────────────────────────────────
2:16:11 PM: ​
2:16:11 PM:   Error message
2:16:11 PM:   Command failed with exit code 137: npm run build (https://ntl.fyi/exit-code-137)
2:16:11 PM: ​
2:16:11 PM:   Error location
2:16:11 PM:   In build.command from netlify.toml:
2:16:11 PM:   npm run build
2:16:11 PM: ​
2:16:11 PM:   Resolved config
2:16:11 PM:   build:
2:16:11 PM:     command: npm run build
2:16:11 PM:     commandOrigin: config
2:16:11 PM:     environment:
2:16:11 PM:       - NODE_OPTIONS
2:16:11 PM:     publish: /opt/build/repo/.next
2:16:11 PM:     publishOrigin: config
2:16:11 PM:   plugins:
2:16:11 PM:     - inputs: {}
2:16:11 PM:       origin: ui
2:16:11 PM:       package: "@netlify/plugin-nextjs"
2:16:11 PM:   redirects:
2:16:11 PM:     - from: /tags
2:16:11 PM:       status: 301
2:16:11 PM:       to: /blog
2:16:12 PM: Failed during stage "building site": Build script returned non-zero exit code: 2
2:16:12 PM:     - from: /tags/*
      status: 301
      to: /blog
    - from: /recipes/*
      status: 301
      to: /tutorial/:splat
    - from: /demo
      status: 301
      to: /tutorial/intro
  redirectsOrigin: config
2:16:12 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
2:16:12 PM: Failing build: Failed to build site
2:16:13 PM: Finished processing build request in 1m33.034s

Basically, after adding sitemap.xml to my site, running the build for PROD on my dev laptop failed. So I added NODE_OPTIONS="--max-old-space-size=4096" and it started working alright.

I then did the same on netlify.toml. Deployments started succeeding. Then they would fail. The behavior is inconsistent. Since the same code for the site works on my laptop, with that same NODE_OPTIONS env config, I’d expect it to always work.

I also increased the memory to 8192 but the behavior is still a hit or miss.

I read that, as a workaround, I could do manual deployments via the Netlify CLI, but I’d rather keep automatic deployments from my Git repo, if possible.

Any suggestion?

Is this a problem on Netlify’s side, that I should report as a bug?

Or is it a problem on my side? (tbh I don’t think it’s an issue with my code, it’s actually a simple site)

Btw, I’ve tried to upgrade Next.js to v14.1.3 (from my current v14.0.3), and those deployments have always failed

Your builds are getting killed:

Adding the enviornment variable that you did won’t have any effect as you can’t increase the system’s memory limits with that. Currently Starter tier gets 8 GiB of RAM and Pro and above get 11 GiB. If your build can’t finish with those constraints, it’d fail as you can see.

Hmmmm, so then the only solutions are to either do manual deploys with Netlify CLI, or upgrade to the Pro plan, right?

Or optimise your build process to not consume 8 GB of memory. But if that’s not possible, then yes, the 2 options that you listed above are the ones to go with.

Ok thanks

blocked.gif