NextJS 14 build errors

I have a simple NextJS app I just upgraded to Next 14. And the build is failing without giving me an error message, just a code:

3:02:48 PM: Netlify Build                                                 
3:02:48 PM: ────────────────────────────────────────────────────────────────
3:02:48 PM: ​
3:02:48 PM: ❯ Version
3:02:48 PM:   @netlify/build 29.26.2
3:02:48 PM: ​
3:02:48 PM: ❯ Flags
3:02:48 PM:   baseRelDir: true
3:02:48 PM:   buildId: 654d3ad001154500085623c1
3:02:48 PM:   deployId: 654d3ad001154500085623c3
3:02:48 PM: ​
3:02:48 PM: ❯ Current directory
3:02:48 PM:   /opt/build/repo
3:02:48 PM: ​
3:02:48 PM: ❯ Config file
3:02:48 PM:   No config file was defined: using default values.
3:02:48 PM: ​
3:02:48 PM: ❯ Context
3:02:48 PM:   production
3:02:48 PM: ​
3:02:48 PM: ❯ Installing plugins
3:02:48 PM:    - @netlify/plugin-nextjs@4.41.1
3:02:59 PM: ​
3:02:59 PM: ❯ Using Next.js Runtime - v4.41.1
3:03:00 PM: ​
3:03:00 PM: @netlify/plugin-nextjs (onPreBuild event)                     
3:03:00 PM: ────────────────────────────────────────────────────────────────
3:03:00 PM: ​
3:03:00 PM: No Next.js cache to restore.
3:03:00 PM: Not running Next Runtime
3:03:00 PM: ​
3:03:00 PM: (@netlify/plugin-nextjs onPreBuild completed in 13ms)
3:03:00 PM: ​
3:03:00 PM: Build command from Netlify app                                
3:03:00 PM: ────────────────────────────────────────────────────────────────
3:03:00 PM: ​
3:03:00 PM: $ yarn build && yarn export
3:03:01 PM: ⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
3:03:02 PM:    Linting and checking validity of types ...
3:03:05 PM:    ▲ Next.js 14.0.2
3:03:05 PM:    Creating an optimized production build ...
3:03:11 PM:  ✓ Compiled successfully
3:03:11 PM:    Collecting page data ...
3:03:15 PM:    Generating static pages (0/3) ...
3:03:16 PM:  ✓ Generating static pages (3/3)
3:03:17 PM:    Finalizing page optimization ...
3:03:17 PM:    Collecting build traces ...
3:03:27 PM: Failed during stage "building site": Build script returned non-zero exit code: 2
3:03:27 PM: ​
3:03:27 PM: "build.command" failed                                        
3:03:27 PM: ────────────────────────────────────────────────────────────────
3:03:27 PM: ​
3:03:27 PM:   Error message
3:03:27 PM:   Command failed with exit code 129: yarn build && yarn export (https://ntl.fyi/exit-code-129)
3:03:27 PM: ​
3:03:27 PM:   Error location
3:03:27 PM:   In Build command from Netlify app:
3:03:27 PM:   yarn build && yarn export
3:03:27 PM: ​
3:03:27 PM:   Resolved config
3:03:27 PM:   build:
3:03:27 PM:     command: yarn build && yarn export
3:03:27 PM:     commandOrigin: ui
3:03:27 PM:     environment:
3:03:27 PM:       - DOPPLER_CONFIG
3:03:27 PM:       - DOPPLER_ENVIRONMENT
3:03:27 PM:       - DOPPLER_PROJECT
3:03:27 PM:       - NETLIFY_NEXT_PLUGIN_SKIP
3:03:27 PM:       - NEXT_PUBLIC_DONATION_GOAL
3:03:27 PM:       - NEXT_PUBLIC_FAUNA_SECRET
3:03:27 PM:       - NEXT_PUBLIC_FAUNA_URL
3:03:27 PM:       - NEXT_PUBLIC_GA_TRACKING_ID
3:03:27 PM:       - NEXT_PUBLIC_PAYPAL_CLIENT_ID
3:03:27 PM:       - NEXT_PUBLIC_SITE_URL
3:03:27 PM:       - NEXT_PUBLIC_TRAILER_URL
3:03:27 PM:     publish: /opt/build/repo/out
3:03:27 PM:     publishOrigin: ui
3:03:27 PM:   plugins:
3:03:27 PM:     - inputs: {}
3:03:27 PM:       origin: ui
3:03:27 PM:       package: "@netlify/plugin-nextjs"
3:03:27 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:03:27 PM: Failing build: Failed to build site
3:03:28 PM: Finished processing build request in 1m2.231s

Could someone help me out with this one, please?

Hi, can you share the site ID? Also have you tried downgrading to the last version of Nextjs?

@SamO, thank you for getting back to me on this. Here is the site ID: c8ad864c-00b6-44d2-a052-c7c0010d5ed7

I have not downgraded NextJS yet. What version would you suggest I try?

Hi @cgen01,

Thanks for providing the site ID.

Could you try downgrading to a Next.js version prior to 13.5 (i.e., 13.4.19 ) and without the ^ to prevent it from installing 13.5? Let us know if you continue to have issues.

@Melvin I’m running into the same issue, for me the downgrade solves the broken builds. Is there a way to follow progress on support for 13.5.x and 14.x on Netlify?

I downgraded to Next 13.4.9 which worked on another one of my sites, but it still fails. I cleared the cache and redeployed also with no luck

Does Netlify support Yarn 4? I just ran updates on another app I have deployed (without upgrading Next, still 13.4.9) and it fails with the same error. Any thoughts?

I downgraded Yarn from Yarn 4 and upgraded Next to v14 and it deploys fine. So, I guess Netlify doesn’t support Yarn 4 yet. Is there a timeline on that support?

The error you had shared has nothing to do with Yarn version. I’d assume downgrading Yarn version had another site-effect which was the actual issue that got fixed.

Do you know when you’ll support Yarn 4?

It should already work, but if not, there’s no timeline as such.