Repository: next.js
Issue: Build failing to complete only in CI
Labels: bug

### Link to the code that reproduces this issue

https://github.com/codecov/codecov-javascript-bundler-plugins/tree/main/integration-tests/test-apps/nextjs

### To Reproduce

We have been unable to reproduce the issue locally, both while attempting to build the app standalone, as well as attempting to run the integration tests locally as well. However, it has been failing consistently in our CI pipeline, while attempting to debug this issue: [Pull Request](https://github.com/codecov/codecov-javascript-bundler-plugins/pull/185).

### Current vs. Expected behavior

Our test application was building fine and passing our integration tests on Next 14:

```
  > nextjs@0.1.0 build /home/runner/work/codecov-javascript-bundler-plugins/codecov-javascript-bundler-plugins/integration-tests/test-apps/nextjs
  > next build
  
  ⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
  Attention: Next.js now collects completely anonymous telemetry regarding usage.
  This information is used to shape Next.js' roadmap and prioritize features.
  You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
  https://nextjs.org/telemetry
  
    ▲ Next.js 14.2.5
  
     Creating an optimized production build ...
  [codecov] Detecting CI provider
  [codecov] Detected CI provider: GitHub Actions
  [codecov] Using commit: 7e994169ed0ed50d070bb2f920342d0968eb04a6
  [codecov] Using compareSha: null
  [codecov] Attempting to fetch `get-pre-signed-url`, attempt: 1
  [codecov] Successfully pre-signed URL fetched
  [codecov] Attempting to fetch `upload-stats`, attempt: 1
  [codecov] Successfully uploaded stats for bundle: test-nextjs-v14-server-cjs
  [codecov] Detecting CI provider
  [codecov] Detected CI provider: GitHub Actions
  [codecov] Using commit: 7e994169ed0ed50d070bb2f920342d0968eb04a6
  [codecov] Using compareSha: null
  [codecov] Attempting to fetch `get-pre-signed-url`, attempt: 1
  [codecov] Successfully pre-signed URL fetched
  [codecov] Attempting to fetch `upload-stats`, attempt: 1
  [codecov] Successfully uploaded stats for bundle: test-nextjs-v14-edge-server-array-push
  [codecov] Detecting CI provider
  [codecov] Detected CI provider: GitHub Actions
  [codecov] Using commit: 7e994169ed0ed50d070bb2f920342d0968eb04a6
  [codecov] Using compareSha: null
  [codecov] Attempting to fetch `get-pre-signed-url`, attempt: 1
  [codecov] Successfully pre-signed URL fetched
  [codecov] Attempting to fetch `upload-stats`, attempt: 1
  [codecov] Successfully uploaded stats for bundle: test-nextjs-v14-client-array-push
   ✓ Compiled successfully
     Linting and checking validity of types ...
  
   ⚠ The Next.js plugin was not detected in your ESLint configuration. See https://nextjs.org/docs/basic-features/eslint#migrating-existing-config
     Collecting page data ...
     Generating static pages (0/5) ...
     Generating static pages (1/5) 
     Generating static pages (2/5) 
     Generating static pages (3/5) 
   ✓ Generating static pages (5/5)
     Finalizing page optimization ...
     Collecting build traces ...
  
  Route (app)                              Size     First Load JS
  ┌ ○ /                                    5.44 kB        92.5 kB
  └ ○ /_not-found                          872 B          87.9 kB
  + First Load JS shared by all            87 kB
    ├ chunks/538-5b4d10cffa6c1cf9.js       31.5 kB
    ├ chunks/7820dfc2-ee432587636317c8.js  53.6 kB
    └ other shared chunks (total)          1.86 kB
  
  
  ○  (Static)  prerendered as static content
  
  (pass) Generating nextjs stats > 14 > matches the snapshot [22997.23ms]
```

However, after updating to Next 15, and also updating other dependencies (React, etc.) our builds are no longer successful, in turn our tests are timing out:

```
> nextjs@0.1.0 build /home/runner/work/codecov-javascript-bundler-plugins/codecov-javascript-bundler-plugins/integration-tests/test-apps/nextjs
  > next build
  
  ⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
  Attention: Next.js now collects completely anonymous telemetry regarding usage.
  This information is used to shape Next.js' roadmap and prioritize features.
  You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
  https://nextjs.org/telemetry
  
     ▲ Next.js 15.0.2
  
     Creating an optimized production build ...
  [codecov] Detecting CI provider
  [codecov] Detected CI provider: GitHub Actions
  [codecov] Using commit: 8e34196ab03754139953f22bff547edf44d7621a
  [codecov] Using compareSha: 7e994169ed0ed50d070bb2f9203[42](https://github.com/codecov/codecov-javascript-bundler-plugins/actions/runs/11615654479/job/32346786999#step:10:43)d0968eb04a6
  [codecov] Attempting to fetch `get-pre-signed-url`, attempt: 1
  [codecov] Successfully pre-signed URL fetched
  [codecov] Attempting to fetch `upload-stats`, attempt: 1
  [codecov] Successfully uploaded stats for bundle: test-nextjs-v15-server-cjs
  [codecov] Detecting CI provider
  [codecov] Detected CI provider: GitHub Actions
  [codecov] Using commit: 8e34196ab03754139953f22bff547edf[44](https://github.com/codecov/codecov-javascript-bundler-plugins/actions/runs/11615654479/job/32346786999#step:10:45)d7621a
  [codecov] Using compareSha: 7e994169ed0ed50d070bb2f920342d0968eb04a6
  [codecov] Attempting to fetch `get-pre-signed-url`, attempt: 1
  [codecov] Successfully pre-signed URL fetched
  [codecov] Attempting to fetch `upload-stats`, attempt: 1
  [codecov] Successfully uploaded stats for bundle: test-nextjs-v15-edge-server-array-push
  [codecov] Detecting CI provider
  [codecov] Detected CI provider: GitHub Actions
  [codecov] Using commit: 8e34196ab03754139953f22bff5[47](https://github.com/codecov/codecov-javascript-bundler-plugins/actions/runs/11615654479/job/32346786999#step:10:48)edf44d7621a
  [codecov] Using compareSha: 7e994169ed0ed50d070bb2f920342d0968eb04a6
  [codecov] Attempting to fetch `get-pre-signed-url`, attempt: 1
  [codecov] Successfully pre-signed URL fetched
  [codecov] Attempting to fetch `upload-stats`, attempt: 1
  [codecov] Successfully uploaded stats for bundle: test-nextjs-v15-client-array-push
   ✓ Compiled successfully
     Linting and checking validity of types ...
     Collecting page data ...
     Generating static pages (0/5) ...
     Generating static pages (1/5) 
     Generating static pages (2/5) 
     Generating static pages (3/5) 
   ✓ Generating static pages (5/5)
     Finalizing page optimization ...
     Collecting build traces ...
  
  Error: 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
        at 
  error: Test "matches the snapshot" timed out after 2[50](https://github.com/codecov/codecov-javascript-bundler-plugins/actions/runs/11615654479/job/32346786999#step:10:51)00ms
```

And occasionally we saw this error appear, however due to the nature of GHA (I believe), we're not able to get the full picture:

![Screenshot 2024-10-28 at 14 13 57](https://github.com/user-attachments/assets/4b13d074-c7b4-4ca0-a97c-6098d4c0c138)


### Provide environment information

```bash
Operating System:
  Platform: linux
  Arch: x64
  Version: #26~22.04.1-Ubuntu SMP Thu Jul 11 22:33:04 UTC 2024
  Available memory (MB): 15982
  Available CPU cores: 4
Binaries:
  Node: 18.20.4
  npm: 10.7.0
  Yarn: 1.22.22
  pnpm: 9.12.3
Relevant Packages:
  next: 15.0.2 // Latest available version is detected (15.0.2).
  eslint-config-next: 14.2.3
  react: 19.0.0-rc-02c0e824-20241028
  react-dom: 19.0.0-rc-02c0e824-20241028
  typescript: 5.3.3
```


### Which area(s) are affected? (Select all that apply)

Not sure

### Which stage(s) are affected? (Select all that apply)

next build (local)

### Additional context

Just to add as well, this build is also failing on Node 20.x.