Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] WebSocket HMR Issues on WSL2 with Plasmo #1166

Open
2 of 3 tasks
H7ioo opened this issue Feb 6, 2025 · 1 comment
Open
2 of 3 tasks

[BUG] WebSocket HMR Issues on WSL2 with Plasmo #1166

H7ioo opened this issue Feb 6, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@H7ioo
Copy link

H7ioo commented Feb 6, 2025

What happened?

Hello there,

Sorry for opening this issue, but I’d like to keep it as a reference in case someone encounters this in the future.

Issue

I'm running Plasmo on WSL2 and accessing the Chrome extension from Microsoft Edge on Windows 11. However, I encountered an issue where HMR (Hot Module Replacement) kept disconnecting, showing:

🟠 WARN   | [plasmo/parcel-runtime]: Connection to the HMR server is closed for /home/USER/path_to_extension/youtube.ts

In the extension page > errors section, I saw:

WebSocket connection to 'ws://localhost:1815/' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
WebSocket connection to 'ws://localhost:1816/' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET

Troubleshooting Attempts

  1. Changed WSL2 networking mode to Mirrored (from NAT) → Worked temporarily but the issue returned.
  2. Disabled antivirus & firewall, added inbound rules → No effect.
  3. Tried various AI-suggested solutions → No success.
  4. Confirmed that it worked fine on Windows (Issue is WSL2-specific).

Solution

After digging around, I found this [Reddit thread](https://www.reddit.com/r/bashonubuntuonwindows/comments/lvyret/comment/gpejbb3/) suggesting that WSL2 behaves as a separate machine, meaning localhost might not resolve as expected.

Fix:

Simply binding the HMR and server hosts to 0.0.0.0 instead of localhost solved the issue:

pnpm dev --hmr-host=0.0.0.0 --hmr-port=1815 --serve-host=0.0.0.0 --serve-port=1012

This allows WebSocket connections from WSL2 to Windows properly.

Why does this work?

IDK to be honest, but if anyone can explain why this is the case, I would really appreciate it.

Version

Latest

What OS are you seeing the problem on?

Windows

What browsers are you seeing the problem on?

Microsoft Edge

Relevant log output

WebSocket connection to 'ws://localhost:1815/' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
WebSocket connection to 'ws://localhost:1816/' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET

(OPTIONAL) Contribution

  • I would like to fix this BUG via a PR

Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I checked the current issues for duplicate problems.
@H7ioo H7ioo added the bug Something isn't working label Feb 6, 2025
@H7ioo H7ioo changed the title [BUG] *WebSocket HMR Issues on WSL2 with Plasmo [BUG] WebSocket HMR Issues on WSL2 with Plasmo Feb 6, 2025
@jeffminim
Copy link

Really lucky to see your post. This has solved my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants