Repository: next.js
Issue: Next 13 Fatal Error: Reached heap limit allocation failed after including UI packages as transpilePackages (Turborepo, PNPM)
Labels: SWC

### Verify canary release

- [X] I verified that the issue exists in the latest Next.js canary release

### Provide environment information

```bash
Operating System:        
      Platform: win32        
      Arch: x64
      Version: Windows 10 Pro
    Binaries:
      Node: 18.16.0
      npm: N/A
      Yarn: N/A
      pnpm: 8.5.0
    Relevant packages:
      next: 13.4.4-canary.0
      eslint-config-next: 13.4.2
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.0.4
```


### Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Package manager (npm, pnpm, Yarn), SWC transpilation

### Link to the code that reproduces this issue or a replay of the bug
[link to codesandbox](https://codesandbox.io/p/github/alikleitcr7/issue-nextjs-tranpiledmodules/main?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522panelType%2522%253A%2522TABS%2522%252C%2522id%2522%253A%2522clhvtswv2000a3n6ked92umy6%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522panelType%2522%253A%2522TABS%2522%252C%2522id%2522%253A%2522clhvtswv2000c3n6k2izwtkki%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clhvtswv2000a3n6ked92umy6%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clhvtswv100093n6kc9dkx411%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252FREADME.md%2522%257D%255D%252C%2522id%2522%253A%2522clhvtswv2000a3n6ked92umy6%2522%252C%2522activeTabId%2522%253A%2522clhvtswv100093n6kc9dkx411%2522%257D%252C%2522clhvtswv2000c3n6k2izwtkki%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clhvtswv2000b3n6kxpaaiu1p%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522PROJECT_SETUP%2522%257D%255D%252C%2522id%2522%253A%2522clhvtswv2000c3n6k2izwtkki%2522%252C%2522activeTabId%2522%253A%2522clhvtswv2000b3n6kxpaaiu1p%2522%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D)

repo: https://github.com/alikleitcr7/issue-nextjs-tranpiledmodules

### To Reproduce

I have a `turborpo` monorepo with a nextjs application, the template I've setup from the nextjs starter template, then composed a new next js application inside the apps and removed the rest. 

I've added some of my components in the `ui` packages (which uses `mui` for styling) and included that package in my next app as transpiledPackages:
```
transpilePackages: ["@products/common-ui"]
```
Then imported one component into the index `page.tsx`:
```
import { SaveButton } from '@products/common-ui';

export default function Home() {
  return (
    <main className={styles.main}>
      <h2>test 21</h2>
      <SaveButton />
    </main>
  );
}
```
building the project is successful, however, when I run `pnpm dev`, it takes long time to compile the `page.tsx`:
```
wait compiling /page 
```

When this is done, make any change to the `page.tsx` content, example: change `<h2>test 21</h2>` to `<h2>test 22</h2>`

this will either take a long time to propagate, or will fail with:
```
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
```



### Describe the Bug

```
store:dev: <--- Last few GCs --->
store:dev: 
store:dev: [1676:0000026E426AE700]   207500 ms: Scavenge (reduce) 1983.0 (2079.5) -> 1982.9 (2080.5) MB, 4.4 / 0.0 ms  (average mu = 0.753, current mu = 0.571) allocation failure;
store:dev: [1676:0000026E426AE700]   208235 ms: Mark-sweep (reduce) 1983.9 (2080.5) -> 1983.6 (2081.5) MB, 732.6 / 0.0 ms  (average mu = 0.668, current mu = 0.164) allocation failure; scavenge might not succeedstore:dev: 
store:dev: 
store:dev: <--- JS stacktrace --->
store:dev: 
store:dev: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
store:dev:  1: 00007FF7F9A6D51F node_api_throw_syntax_error+175743
store:dev:  2: 00007FF7F99F2E66 v8::internal::wasm::WasmCode::safepoint_table_offset+59654
store:dev:  3: 00007FF7F99F4B72 v8::internal::wasm::WasmCode::safepoint_table_offset+67090
store:dev:  4: 00007FF7FA49AAB4 v8::Isolate::ReportExternalAllocationLimitReached+116
store:dev:  5: 00007FF7FA485E12 v8::Isolate::Exit+674
store:dev:  6: 00007FF7FA307C6C v8::internal::EmbedderStackStateScope::ExplicitScopeForTesting+124
store:dev:  7: 00007FF7FA304E8B v8::internal::Heap::CollectGarbage+3963
store:dev:  8: 00007FF7FA31B0C3 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath+2099
store:dev:  9: 00007FF7FA31B96D v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath+93
store:dev: 10: 00007FF7FA3242BA v8::internal::Factory::AllocateRaw+810
store:dev: 11: 00007FF7FA3376FD v8::internal::FactoryBase<v8::internal::Factory>::NewHeapNumber<0>+685
store:dev: 12: 00007FF7FA33BBA8 v8::internal::FactoryBase<v8::internal::Factory>::NewRawTwoByteString+72
store:dev: 13: 00007FF7F9FD33EB v8::internal::StringStream::ClearMentionedObjectCache+9291
store:dev: 14: 00007FF7FA223CD8 v8::sampler::Sampler::Stop+2824
store:dev: 15: 00007FF7FA226AA7 v8::sampler::Sampler::Stop+14551
store:dev: 16: 00007FF7FA2276F0 v8::sampler::Sampler::Stop+17696
store:dev: 17: 00007FF7FA2276F0 v8::sampler::Sampler::Stop+17696
store:dev: 18: 00007FF7FA229B36 v8::base::TimeDelta::operator!=+8262
store:dev: 19: 00007FF7FA42F0BF v8::internal::Builtins::code+99375
store:dev: 20: 00007FF7FA538151 v8::internal::SetupIsolateDelegate::SetupHeap+558449
store:dev: 21: 00007FF77B5D4D70
```

### Expected Behavior

Excluding the `ui` package from  `transpilePackages` will make the project run smoothly and fast, expected same behavior.

### Which browser are you using? (if relevant)

Microsoft Edge Version 113.0.1774.42 (Official build) (64-bit)

### How are you deploying your application? (if relevant)

_No response_