Repository: next.js
Issue: Build not exiting on errors inside Suspense
Labels: bug

### Verify canary release

- [X] I verified that the issue exists in the latest Next.js canary release

### Provide environment information

```bash
Operating System:
      Platform: linux
      Arch: x64
      Version: #1 SMP Fri Jan 27 02:56:13 UTC 2023
    Binaries:
      Node: 18.12.0
      npm: 9.7.1
      Yarn: 1.22.19
      pnpm: 8.6.8
    Relevant Packages:
      next: 13.4.10-canary.8
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: N/A
    Next.js Config:
      output: N/A
```


### Which area(s) of Next.js are affected? (leave empty if unsure)

_No response_

### Link to the code that reproduces this issue or a replay of the bug

https://github.com/roch-numbered/next-build-with-suspense

### To Reproduce

1. Run `npm run build`.
2. The task outputs an error `info Generating static pages (0/3)TypeError:`.
3. The build passes.

_Note: I intentionally added an error in the code to make this bug testable._

### Describe the Bug

The build passes instead of exiting.

### Expected Behavior

When a Next.js app is built, errors should prevent the task to finalize the build and exit the process.

It's important to note that removing the `<Suspense>` boundary makes the build process to crash. Also, it seems to required a `_app.tsx` file, I first tried to use `<Suspense />` inside the `pages/index.tsx` file but the bug wasn't reproducible.

### Intentional code error

As mentioned previously, the code is intentionally not working in order to demonstrate my issue.

To fully describe my use case, imagine that `title` variable is an array coming from an external source (CMS, API etc.). If the value is changed to a `string` (or whatever other type), the page generation (or revalidation) should crash and not pass (which isn't currently the case).

---

### Personal understanding

I may be wrong about the use of `Suspense` in this context.
1. Is it normal that the build process passes?
2. Should it be used with App Router and React Server Component only to avoid this?

---

### ISR

A last note/question on revalidation and ISR, from [the documentation](https://nextjs.org/docs/pages/building-your-application/rendering/incremental-static-regeneration), I'm seeing this:

> When a request is made to a page that was pre-rendered at build time, it will initially show the cached page.
>
> - Any requests to the page after the initial request and before 10 seconds are also cached and instantaneous.
> - After the 10-second window, the next request will still show the cached (stale) page
> - Next.js triggers a regeneration of the page in the background.
> - Once the page generates successfully, Next.js will invalidate the cache and show the updated page. **If the background regeneration fails, the old page would still be unaltered.**

From a previous experience, I've faced an issue where a field value has changed (let's say from an array to a string) between the build and the revalidation and made the whole app to crash. While the first build was well working, Next.js still promoted to front-end a broken revalidated version of the page.

My question here may sound a bit off topic but is it the expected behavior of Next.js? Or is it related to this build-not-exiting issue?
Because from what I see on [the documentation (Error handling and revalidation)](https://nextjs.org/docs/pages/building-your-application/rendering/incremental-static-regeneration#error-handling-and-revalidation):

> If there is an error inside `getStaticProps` when handling background regeneration

Does "background regeneration failing" only mention errors happening inside `getStaticProps` or also includes render errors?

Note: If you prefer me to discuss that second topic on a discussion, I can split this into two parts, it just feels connected to me.

### Which browser are you using? (if relevant)

_No response_

### How are you deploying your application? (if relevant)

Vercel