Skip to content

fix(test): resolve ws CJS named export error with cloudflare preset#855

Open
fengmk2 wants to merge 2 commits intomainfrom
fix-bug-831
Open

fix(test): resolve ws CJS named export error with cloudflare preset#855
fengmk2 wants to merge 2 commits intomainfrom
fix-bug-831

Conversation

@fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Mar 14, 2026

closes #831

When Nuxt's cloudflare preset is active, vitest passes --conditions browser
to worker processes. This caused ws to resolve to its browser stub
(ws/browser.js) instead of the ESM wrapper (ws/wrapper.mjs), because
the test package's node export condition loaded index-node.js which
imports @vitest/browser/index.jsws.

Fix by adding a browser export condition before node in the test
package's main export. When --conditions browser is active, browser
matches first and resolves to dist/index.js (which doesn't pull in
@vitest/browser), avoiding the ws resolution issue.

Also fix ecosystem-ci patch-project.ts to apply pnpm overrides for
projects that already use Vite+ (previously skipped by vp migrate),
and add the reproduction repo as an e2e test case.

@netlify
Copy link

netlify bot commented Mar 14, 2026

Deploy Preview for viteplus-preview canceled.

Name Link
🔨 Latest commit a97c6cd
🔍 Latest deploy log https://app.netlify.com/projects/viteplus-preview/deploys/69b6a8504984500008e1e64b

@fengmk2 fengmk2 self-assigned this Mar 14, 2026
Copy link
Member Author

fengmk2 commented Mar 14, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@fengmk2 fengmk2 marked this pull request as ready for review March 14, 2026 08:40
@fengmk2 fengmk2 requested a review from Brooooooklyn March 14, 2026 08:40
Copy link
Member Author

fengmk2 commented Mar 14, 2026

@fengmk2 fengmk2 force-pushed the fix-bug-831 branch 2 times, most recently from a33e566 to 8024203 Compare March 14, 2026 10:30
closes #831

When Nuxt's cloudflare preset is active, vitest passes `--conditions browser`
to worker processes. This caused `ws` to resolve to its browser stub
(`ws/browser.js`) instead of the ESM wrapper (`ws/wrapper.mjs`), because
the test package's `node` export condition loaded `index-node.js` which
imports `@vitest/browser/index.js` → `ws`.

Fix by adding a `browser` export condition before `node` in the test
package's main export. When `--conditions browser` is active, `browser`
matches first and resolves to `dist/index.js` (which doesn't pull in
`@vitest/browser`), avoiding the ws resolution issue.

Also fix ecosystem-ci `patch-project.ts` to apply pnpm overrides for
projects that already use Vite+ (previously skipped by `vp migrate`),
and add the reproduction repo as an e2e test case.
Copy link
Member Author

fengmk2 commented Mar 14, 2026

1 similar comment
Copy link
Member Author

fengmk2 commented Mar 14, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vp test fails with ws CJS named export error when nitro.preset is cloudflare_module

1 participant