Frontend Development 4 min read

Vite Port Detection Issue Caused by Host Configuration in Micro‑Frontend Projects

During development of a micro‑frontend project using wujie, the child app required port 5173 for communication, but newly created Vite React‑TS projects failed to auto‑increment the port, revealing that Vite’s port‑detection logic also depends on the host setting, not just the port number.

Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Vite Port Detection Issue Caused by Host Configuration in Micro‑Frontend Projects

Problem: In a micro‑frontend setup using wujie, the child project must run on port 5173 for inter‑project communication, but when a new Vite React‑TS project was started, Vite did not automatically switch to an available port, leaving the port unchanged.

Investigation: The author created a Vite project with npm create vite@latest react_demos -- --template react-ts and started it using npm run dev , observing that the port remained 5173. Various Vite configuration attempts were made, including adding host settings in vite.config.ts , but the expected error did not appear.

Further research showed that the issue was unrelated to Vite version numbers (both Vite 3 and Vite 4 were tested). Adding a host configuration of 0.0.0.0 prevented Vite from attempting to find a free port, while the default host (localhost) allowed Vite to auto‑increment the port.

Result: Vite’s port detection mechanism first compares the host value; if one project specifies a custom host (e.g., 0.0.0.0) and another uses the default localhost, Vite treats the ports as matching and does not try the next available port. Setting both projects to the same host (localhost) enables Vite to automatically select a free port.

Conclusion: When encountering similar port conflicts in micro‑frontend development, consider the host configuration as a factor in Vite’s port‑selection logic, and adjust the host settings accordingly to allow automatic port fallback.

TypeScriptfrontend developmentReactmicro-frontendviteHost ConfigurationPort Detection
Rare Earth Juejin Tech Community
Written by

Rare Earth Juejin Tech Community

Juejin, a tech community that helps developers grow.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.