Commit 2bd2792
authored
fix(test): use platform neutral for vendor leaf dep bundling to fix browser tests (#635)
The leaf dependency bundling step used `platform: 'node'`, which caused
rolldown to generate a shared runtime chunk with `createRequire` from
`node:module`. Since vendor files (pathe, chai, tinyrainbow, etc.) are
loaded by @vitest/runner and @vitest/expect in the browser during vitest
browser mode, the browser hit the externalized `node:module` and threw:
Module "node:module" has been externalized for browser compatibility.
Cannot access "node:module.createRequire" in client code.
This caused browser tests to hang indefinitely.
Changes:
- Switch `platform: 'node'` to `platform: 'neutral'` so rolldown emits
pure JS CJS interop helpers without Node.js built-in imports
- Add `mainFields: ['module', 'main']` so CJS-only packages like
expect-type can still be resolved under neutral platform
- Fix `fixCjsNamedExports()` to handle the case where rolldown emits
`export default require_xxx()` without an accompanying `export {}`
block (the previous regex required both patterns to match)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes the bundling configuration and post-processing of generated vendor code; risk is moderate because it can affect module resolution and runtime behavior across both Node and browser test environments.
>
> **Overview**
> Fixes vitest browser-mode hangs by changing the leaf-dependency bundling step to emit browser-safe output.
>
> `bundleLeafDeps()` now builds with `platform: 'neutral'` (avoiding Node-only helpers like `node:module.createRequire`) and adds `resolve.mainFields: ['module','main']` so CJS-only packages still resolve correctly. The `fixCjsNamedExports()` post-processing was broadened to also patch outputs that contain `export default require_xxx()` without an `export {}` block, ensuring named exports like `expectTypeOf` are consistently re-exported.
>
> <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit ace4c36. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 5844065 commit 2bd2792
1 file changed
Lines changed: 17 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
720 | 720 | | |
721 | 721 | | |
722 | 722 | | |
723 | | - | |
| 723 | + | |
724 | 724 | | |
725 | 725 | | |
726 | 726 | | |
| |||
736 | 736 | | |
737 | 737 | | |
738 | 738 | | |
| 739 | + | |
739 | 740 | | |
740 | 741 | | |
741 | 742 | | |
| |||
1150 | 1151 | | |
1151 | 1152 | | |
1152 | 1153 | | |
1153 | | - | |
1154 | 1154 | | |
1155 | | - | |
| 1155 | + | |
1156 | 1156 | | |
1157 | 1157 | | |
1158 | 1158 | | |
1159 | | - | |
1160 | | - | |
1161 | | - | |
1162 | | - | |
1163 | | - | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
1164 | 1173 | | |
1165 | 1174 | | |
1166 | 1175 | | |
| |||
0 commit comments