Repository: next.js
Issue: WorkerError after updating Next.js from v13.2.4 to v13.4.16
Labels: bug,Output (export/standalone)

### Verify canary release

- [X] I verified that the issue exists in the latest Next.js canary release

### Provide environment information

```bash
Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.5.0: Thu Jun  8 22:21:34 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T8112
    Binaries:
      Node: 18.16.1
      npm: 9.5.1
      Yarn: 1.22.19
      pnpm: 7.27.1
    Relevant Packages:
      next: 13.4.16
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 4.9.5
    Next.js Config:
      output: N/A
```


### Which area(s) of Next.js are affected? (leave empty if unsure)

Standalone mode (output: "standalone")

### Link to the code that reproduces this issue or a replay of the bug

https://github.com/issueset/nextjs-workererror

### To Reproduce

I've create a minimal reproduction for this issue

1. Open https://stackblitz.com/github/issueset/nextjs-workererror/tree/next-13-2?startScript=build 

   This is a repo using Next.js v13.2.4. Running `pnpm build` has no issue.

   
   <img width="1489" alt="image" src="https://github.com/vercel/next.js/assets/24715727/118f1b3b-3256-427f-9d9b-f89606450789">

2. Open https://stackblitz.com/github/issueset/nextjs-workererror/tree/next-13-4-16?file=package.json&startScript=build

   This is the same repo but with the latest Next.js v13.4.16. `pnpm build` will fail and output the following message. 

   <img width="1860" alt="Screenshot 2023-08-16 at 22 17 44" src="https://github.com/vercel/next.js/assets/24715727/04033f90-f51c-48ff-a4fb-cfa374c8c32d">



   

```
/Users/ocavue/code/play/nextjs-workererror/.next/server/pages/page2.js:55
    console.log("window.addEventListener", typeof window.addEventListener);
                                                  ^

ReferenceError: window is not defined
    at callWindow (/Users/ocavue/code/play/nextjs-workererror/.next/server/pages/page2.js:55:51)
    at runNextTicks (node:internal/process/task_queues:60:5)
    at listOnTimeout (node:internal/timers:538:9)
    at process.processTimers (node:internal/timers:512:7)

Node.js v18.16.1

> Build error occurred
Error: Call retries were exceeded
    at ChildProcessWorker.initialize (/Users/ocavue/code/play/nextjs-workererror/node_modules/.pnpm/next@13.4.16-canary.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/jest-worker/index.js:1:11661)
    at ChildProcessWorker._onExit (/Users/ocavue/code/play/nextjs-workererror/node_modules/.pnpm/next@13.4.16-canary.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/compiled/jest-worker/index.js:1:12599)
    at ChildProcess.emit (node:events:513:28)
    at ChildProcess.emit (node:domain:489:12)
    at ChildProcess._handle.onexit (node:internal/child_process:291:12) {
  type: 'WorkerError'
}
[    ] - info Generating static pages (3/4) ELIFECYCLE  Command failed with exit code 1.
```




### Describe the Bug

Update updating Next.js to the latest v13.4.16, `pnpm run build` doesn't work anymore. However, the Vercel deployment seems to be fine. 

### Expected Behavior

No error occurs. 

### Which browser are you using? (if relevant)

_No response_

### How are you deploying your application? (if relevant)

_No response_