Failed to deploy Next.js site (exit code 137)

We are build our new documentation using Next.js and we are having issues deploying it. For some reason it exit with a code 137 always when it is building the static pages.

Site: https://storybook-web.netlify.app
The building process is quite simple. I only have a prebuild script that would fetch our docs from our monorepo. This part works well.

Here’s the logs I received:

6:23:19 PM: build-image version: ebe1739aa70e1db449262aa2ac466dad070382fb (focal)
6:23:19 PM: buildbot version: 211f66487a631406c3c0b2b43c8b33d0bb175356
6:23:19 PM: Fetching cached dependencies
6:23:19 PM: Starting to download cache of 350.7MB
6:23:23 PM: Finished downloading cache in 3.281s
6:23:23 PM: Starting to extract cache
6:23:30 PM: Finished extracting cache in 6.999s
6:23:30 PM: Finished fetching cache in 10.35s
6:23:30 PM: Starting to prepare the repo for build
6:23:30 PM: Preparing Git Reference refs/heads/main
6:23:31 PM: Starting to install dependencies
6:23:32 PM: Python version set to 3.8
6:23:32 PM: Attempting Ruby version 2.7.2, read from environment
6:23:32 PM: Using Ruby version 2.7.2
6:23:33 PM: Started restoring cached go cache
6:23:33 PM: Finished restoring cached go cache
6:23:33 PM: go version go1.19.13 linux/amd64
6:23:33 PM: Using PHP version 8.0
6:23:34 PM: Started restoring cached Node.js version
6:23:35 PM: Finished restoring cached Node.js version
6:23:35 PM: v18.19.0 is already installed.
6:23:35 PM: Now using node v18.19.0 (npm v10.2.3)
6:23:35 PM: Enabling Node.js Corepack
6:23:36 PM: Started restoring cached build plugins
6:23:36 PM: Finished restoring cached build plugins
6:23:36 PM: Started restoring cached corepack dependencies
6:23:36 PM: Finished restoring cached corepack dependencies
6:23:36 PM: Started restoring cached pnpm cache
6:23:36 PM: Finished restoring cached pnpm cache
6:23:36 PM: Installing npm packages using pnpm version 8.14.0
6:23:37 PM: Lockfile is up to date, resolution step is skipped
6:23:37 PM: Progress: resolved 1, reused 0, downloaded 0, added 0
6:23:37 PM: Packages: +1164
6:23:37 PM: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6:23:38 PM: Progress: resolved 1164, reused 667, downloaded 0, added 0
6:23:39 PM: Progress: resolved 1164, reused 1163, downloaded 0, added 1162
6:23:39 PM: Progress: resolved 1164, reused 1163, downloaded 0, added 1164, done
6:23:40 PM: dependencies:
6:23:40 PM: + @radix-ui/react-accordion 1.1.2
6:23:40 PM: + @radix-ui/react-aspect-ratio 1.0.3
6:23:40 PM: + @radix-ui/react-dialog 1.0.5
6:23:40 PM: + @radix-ui/react-dropdown-menu 2.0.6
6:23:40 PM: + @radix-ui/react-navigation-menu 1.1.4
6:23:40 PM: + @radix-ui/react-scroll-area 1.0.5
6:23:40 PM: + @radix-ui/react-slot 1.0.2
6:23:40 PM: + @storybook/icons 1.2.3
6:23:40 PM: + chalk 5.3.0
6:23:40 PM: + chalk-animation 2.0.3
6:23:40 PM: + class-variance-authority 0.7.0
6:23:40 PM: + clsx 2.1.0
6:23:40 PM: + cookies-next 4.1.0
6:23:40 PM: + copy-to-clipboard 3.3.3
6:23:40 PM: + date-fns 2.30.0
6:23:40 PM: + date-fns-tz 2.0.0
6:23:40 PM: + directory-tree 3.5.1
6:23:40 PM: + framer-motion 10.18.0
6:23:40 PM: + fs-extra 11.2.0
6:23:40 PM: + fs-find-root 2.0.0
6:23:40 PM: + gray-matter 4.0.3
6:23:40 PM: + highlight.js 11.9.0
6:23:40 PM: + image-size 1.1.1
6:23:40 PM: + next 14.0.4
6:23:40 PM: + next-mdx-remote 4.4.1
6:23:40 PM: + next-themes 0.2.1
6:23:40 PM: + node-fetch 3.3.2
6:23:40 PM: + prismjs 1.29.0
6:23:40 PM: + react 18.2.0
6:23:40 PM: + react-dom 18.2.0
6:23:40 PM: + react-syntax-highlighter 15.5.0
6:23:40 PM: + rehype-autolink-headings 7.1.0
6:23:40 PM: + rehype-highlight 7.0.0
6:23:40 PM: + rehype-pretty-code 0.12.3
6:23:40 PM: + rehype-slug 6.0.0
6:23:40 PM: + shikiji 0.9.19
6:23:40 PM: + tailwind-merge 2.2.0
6:23:40 PM: + tailwindcss-animate 1.0.7
6:23:40 PM: + tar 6.2.0
6:23:40 PM: + tsx 4.7.0
6:23:40 PM: + zod 3.22.4
6:23:40 PM: devDependencies:
6:23:40 PM: + @storybook/addon-controls 8.0.0-alpha.9
6:23:40 PM: + @storybook/nextjs-server 0.0.4
6:23:40 PM: + @storybook/react 8.0.0-alpha.9
6:23:40 PM: + @types/chalk-animation 1.6.3
6:23:40 PM: + @types/fs-extra 11.0.4
6:23:40 PM: + @types/node 20.11.0
6:23:40 PM: + @types/prismjs 1.26.3
6:23:40 PM: + @types/react 18.2.47
6:23:40 PM: + @types/react-dom 18.2.18
6:23:40 PM: + @types/react-syntax-highlighter 15.5.11
6:23:40 PM: + @types/tar 6.1.10
6:23:40 PM: + autoprefixer 10.4.16
6:23:40 PM: + eslint 8.56.0
6:23:40 PM: + eslint-config-next 14.0.4
6:23:40 PM: + postcss 8.4.33
6:23:40 PM: + storybook 8.0.0-alpha.9
6:23:40 PM: + tailwindcss 3.4.1
6:23:40 PM: + typescript 5.3.3
6:23:40 PM: Done in 3.5s
6:23:40 PM: npm packages installed using pnpm
6:23:41 PM: Successfully installed dependencies
6:23:41 PM: Starting build script
6:23:41 PM: Detected 1 framework(s)
6:23:41 PM: "next" at version "14.0.4"
6:23:41 PM: Section completed: initializing
6:23:43 PM: ​
6:23:43 PM: Netlify Build                                                 
6:23:43 PM: ────────────────────────────────────────────────────────────────
6:23:43 PM: ​
6:23:43 PM: ❯ Version
6:23:43 PM:   @netlify/build 29.32.0
6:23:43 PM: ​
6:23:43 PM: ❯ Flags
6:23:43 PM:   baseRelDir: true
6:23:43 PM:   buildId: 65a5781564401d00075d8011
6:23:43 PM:   deployId: 65a5781564401d00075d8013
6:23:43 PM: ​
6:23:43 PM: ❯ Current directory
6:23:43 PM:   /opt/build/repo
6:23:43 PM: ​
6:23:43 PM: ❯ Config file
6:23:43 PM:   No config file was defined: using default values.
6:23:43 PM: ​
6:23:43 PM: ❯ Context
6:23:43 PM:   production
6:23:43 PM: ​
6:23:43 PM: ❯ Using Next.js Runtime - v4.41.3
6:23:44 PM: ​
6:23:44 PM: @netlify/plugin-nextjs (onPreBuild event)                     
6:23:44 PM: ────────────────────────────────────────────────────────────────
6:23:44 PM: ​
6:23:44 PM: Next.js cache restored.
6:23:44 PM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
6:23:44 PM: ​
6:23:44 PM: (@netlify/plugin-nextjs onPreBuild completed in 304ms)
6:23:44 PM: ​
6:23:44 PM: Build command from Netlify app                                
6:23:44 PM: ────────────────────────────────────────────────────────────────
6:23:44 PM: ​
6:23:44 PM: $ CI="" pnpm run build
6:23:45 PM: > storybook-web@0.1.0 build /opt/build/repo
6:23:45 PM: > pnpm fetch-docs && next build
6:23:45 PM: > storybook-web@0.1.0 fetch-docs /opt/build/repo
6:23:45 PM: > tsx scripts/getLocalDocs.ts
6:23:46 PM: Fetching docs for 8.0-test-1...
6:23:46 PM: Fetching docs for 8.0-test-2...
6:23:46 PM: Fetching docs for 8.0-test-3...
6:23:49 PM: Done!
6:23:50 PM:    ▲ Next.js 14.0.4
6:23:50 PM:    Creating an optimized production build ...
6:23:55 PM: warn - The class `ease-[cubic-bezier(0.87,_0,_0.13,_1)]` is ambiguous and matches multiple utilities.
6:23:55 PM: warn - If this is content and not a class, replace it with `ease-[cubic-bezier(0.87,_0,_0.13,_1)]` to silence this warning.
6:23:56 PM:  ✓ Compiled successfully
6:23:56 PM:    Linting and checking validity of types ...
6:23:58 PM: ./components/home/automate/merge-and-ship.tsx
6:23:58 PM: 100:15  Warning: Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
6:23:58 PM: 106:15  Warning: Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
6:23:58 PM: 144:17  Warning: Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
6:23:58 PM: 153:17  Warning: Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
6:23:58 PM: 181:15  Warning: Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
6:23:58 PM: ./components/home/automate/publish.tsx
6:23:58 PM: 66:11  Warning: Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
6:23:58 PM: 72:11  Warning: Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
6:23:58 PM: ./components/home/automate/ui-review.tsx
6:23:58 PM: 13:9  Warning: Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
6:23:58 PM: 23:13  Warning: Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
6:23:58 PM: 23:13  Warning: img elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
6:23:58 PM: ./components/home/demo/hero-demo.tsx
6:23:58 PM: 198:7  Warning: Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
6:23:58 PM: ./components/home/share/embed-integrations.tsx
6:23:58 PM: 77:9  Warning: Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
6:23:58 PM: 97:9  Warning: Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
6:23:58 PM: 117:9  Warning: Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
6:23:58 PM: 137:9  Warning: Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
6:23:58 PM: ./components/home/share/integrations-carousel.tsx
6:23:58 PM: 43:13  Warning: Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
6:23:58 PM: ./components/home/share/player.tsx
6:23:58 PM: 119:7  Warning: Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
6:23:58 PM: 119:7  Warning: img elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
6:23:58 PM: ./components/home/share/publish-integrations.tsx
6:23:58 PM: 32:7  Warning: Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
6:23:58 PM: info  - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
6:23:58 PM:    Collecting page data ...
6:24:01 PM:    Generating static pages (0/640) ...
6:24:11 PM:    Generating static pages (160/640)
6:24:20 PM:    Generating static pages (320/640)
6:24:38 PM:    Generating static pages (480/640)
6:26:26 PM: Killed
6:26:26 PM:  ELIFECYCLE  Command failed with exit code 137. (https://ntl.fyi/exit-code-137)
6:26:26 PM: ​
6:26:26 PM: "build.command" failed                                        
6:26:26 PM: ────────────────────────────────────────────────────────────────
6:26:26 PM: ​
6:26:26 PM:   Error message
6:26:26 PM:   Command failed with exit code 1: CI="" pnpm run build (https://ntl.fyi/exit-code-1)
6:26:26 PM: ​
6:26:26 PM:   Error location
6:26:26 PM:   In Build command from Netlify app:
6:26:26 PM:   CI="" pnpm run build
6:26:26 PM: ​
6:26:26 PM:   Resolved config
6:26:26 PM:   build:
6:26:26 PM:     command: CI="" pnpm run build
6:26:26 PM:     commandOrigin: ui
6:26:26 PM:     environment:
6:26:26 PM:       - GITHUB_STORYBOOK_BOT_PAT
6:26:26 PM:       - GOOGLE_TAG_TRACKING_ID
6:26:26 PM:       - NEXT_PRIVATE_TARGET
6:26:26 PM:     publish: /opt/build/repo/.next
6:26:26 PM:     publishOrigin: ui
6:26:26 PM:   plugins:
6:26:26 PM:     - inputs: {}
6:26:26 PM:       origin: ui
6:26:26 PM:       package: "@netlify/plugin-nextjs"
6:26:27 PM: Failed during stage "building site": Build script returned non-zero exit code: 2
6:26:27 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
6:26:27 PM: Failing build: Failed to build site
6:26:27 PM: Finished processing build request in 3m8.04s

Here’s a picture of our build setup

I don’t think this is something related to our code per say since I tried the exact same code and set up on Vercel and the site build in about 3 minutes. We are on an enterprise plan but I can see that our bandwidth and build/min are out of limits.

Could it be a simple issue around limits or is it something code related? All other resources I could find point to a memory issue but as we are in an enterprise plan I thought this could not be an issue.

Also, I don’t have a local netlify config file.

Any idea what this could be?

Your build ran out of memory. Unfortunately, that’s all we can tell about this. As for what exactly made it go over the mark is not something we can investigate. I can see that you’re using the Standard Build pod with only 11 GB memory. We can probably ping your account manager to get you on High Performance builds if that’s possible as that would give you 36 GB of RAM.

Thanks for your reply. Unfortunately this is not quite useful for us since building locally and on Vercel are really fast. If this build doesn’t work with 11GB out of the box, this must be something related to Netlify.

All the code is public, is there any chance you saw similar issues in the past with potential ways to solve it?

Thanks

Thanks so much for your patience, and apologies for the delayed response here. On paid plans such Enterprise (non-High Performance Builds) you get 11 GB of memory and 6 CPU’s. Two solutions here are to either decrease your build memory to get below the 11 GB limit or opt for High Performance Builds which increases the limit to 36 GB.

If you’d like to locate where you’re running into memory limitations, you can try using the Netlify Docker image and setting memory limitations to pinpoint where the project fails: netlify/build Tags (docker.com) (docs: netlify/build-image: This is the build image used for running automated builds (github.com))

The only other alternative we can offer you at the moment is to either build locally or on another CI platform like GitHub Actions and deploy to Netlify via CLI. If you are interested in checking out the Enterprise plan with the High Performance Builds add-on that gives you 36 GB of memory let us know and we can let the sales team know to reach out to you.

Apologies again for the long silence. I am hoping one of the alternatives we suggest can help you out! Thanks so much!