Skip to content

fix(vite-plugin-cloudflare): avoid The WebSocket is undefined error during build#12521

Merged
edmundhung merged 4 commits intomainfrom
edmundhung/fix-build-error-websocket-undefined
Feb 11, 2026
Merged

fix(vite-plugin-cloudflare): avoid The WebSocket is undefined error during build#12521
edmundhung merged 4 commits intomainfrom
edmundhung/fix-build-error-websocket-undefined

Conversation

@edmundhung
Copy link
Member

@edmundhung edmundhung commented Feb 10, 2026

Fixes #8909.

CloudflareDevEnvironment requires initRunner() to be called via the dev plugin's configureServer hook to establish its WebSocket connection.

Frameworks like React Router create a child Vite dev server during builds to compile route files, and strip configureServer from all plugins to avoid conflicts. This means initRunner() never runs, leaving the WebSocket uninitialized. When Vite's dep optimizer or module pruning calls hot.send(), the assertion fails.

The fix checks whether configureServer is still present on the dev plugin at environment creation time. If it's been stripped, we fall back to a standard vite environment.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: bugfix

A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

@changeset-bot
Copy link

changeset-bot bot commented Feb 10, 2026

🦋 Changeset detected

Latest commit: daf9a49

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 10, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12521

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12521

miniflare

npm i https://pkg.pr.new/miniflare@12521

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12521

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12521

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12521

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12521

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12521

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@12521

wrangler

npm i https://pkg.pr.new/wrangler@12521

commit: daf9a49

@claude
Copy link
Contributor

claude bot commented Feb 10, 2026

Claude finished @edmundhung's task —— View job


Changeset Review Complete

  • Read changeset guidelines
  • Read and validate changeset file
  • Provide feedback

✅ All changesets look good

The changeset for .changeset/fix-child-compiler-websocket-assertion.md is properly formatted:

  • Version Type: Correctly marked as patch (bug fix)
  • Changelog Quality: Clear title and helpful explanation of the issue and scenario
  • Markdown Headers: No h1/h2/h3 headers used ✓
  • Package: Correctly targets @cloudflare/vite-plugin
  • Format: Follows the recommended single-sentence title + explanatory body format

@edmundhung edmundhung marked this pull request as ready for review February 11, 2026 10:48
@edmundhung edmundhung requested a review from a team as a code owner February 11, 2026 10:48
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

@edmundhung edmundhung changed the title fix: avoid The WebSocket is undefined error during build fix(vite-plugin-cloudflare): avoid The WebSocket is undefined error during build Feb 11, 2026
@edmundhung edmundhung force-pushed the edmundhung/fix-build-error-websocket-undefined branch from 79d3988 to 7ba4fbc Compare February 11, 2026 13:41
@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Feb 11, 2026
@edmundhung edmundhung force-pushed the edmundhung/fix-build-error-websocket-undefined branch from 0033b99 to 6cad633 Compare February 11, 2026 15:37
@edmundhung edmundhung force-pushed the edmundhung/fix-build-error-websocket-undefined branch from 6cad633 to daf9a49 Compare February 11, 2026 19:50
@edmundhung edmundhung merged commit a8183db into main Feb 11, 2026
43 of 45 checks passed
@edmundhung edmundhung deleted the edmundhung/fix-build-error-websocket-undefined branch February 11, 2026 22:07
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

vite-plugin exception thrown when doing npm run build

2 participants