Vite does not release ports when the server is stopped (v20.0.0)
Current Behavior
Vite is not releasing ports when the server is stopped. So when I start it again, it looks for the next available port, ie:
> nx run company-web:serve
> vite serve
Port 3000 is in use, trying another one...
Port 3001 is in use, trying another one...
VITE v5.3.5 ready in 1689 ms
➜ Local: http://localhost:3002/company
Expected Behavior
When stopping the server, the port should be made available again, so when starting again, the server is running on the same port.
GitHub Repo
https://github.com/ksdc-grantw/vite-server-bug
Steps to Reproduce
- Checkout
https://github.com/ksdc-grantw/vite-server-bugand runnpm installThis is a fresh workspace generated bynpx create-nx-workspace@latest - Run the app,
nx serve vite-app - Stop the app
- Restart the app
Note the info line in the console: Port 4200 is in use, trying another one...
Nx Report
> nx report
NX Report complete - copy this into the issue template
Node : 20.15.1
OS : win32-x64
Native Target : x86_64-windows
npm : 10.7.0
nx (global) : 20.0.0
nx : 20.0.0
@nx/js : 20.0.0
@nx/jest : 20.0.0
@nx/eslint : 20.0.0
@nx/workspace : 20.0.0
@nx/devkit : 20.0.0
@nx/eslint-plugin : 20.0.0
@nx/react : 20.0.0
@nx/vite : 20.0.0
@nx/web : 20.0.0
typescript : 5.5.4
---------------------------------------
Registered Plugins:
@nx/vite/plugin
@nx/eslint/plugin
@nx/jest/plugin
Failure Logs
No response
Package Manager Version
10.7.0
Operating System
- [ ] macOS
- [ ] Linux
- [x] Windows
- [ ] Other (Please specify)
Additional Information
I recently upgraded from 19.6.2 to 20.0.0 and didnt see anything in the release notes between those 2 versions that would explain this.
I created a fresh workspace for 19.6.2 and the bug did not occur.
Same issue. Pressing CTRL+C to stop the server does not stop the server.
Same issues. The error occurs everywhere using the terminal. I use nx 19.8.4.
Temporarily handle this error by using: npx kill-port <port>
I am also facing same issue in nx 19.8.4. I have to manully kill the processes
Same issue when using rspack
After migrating to latest Nx (20.0.6 at time of trying) I cannot reproduce this. I could in v20. I opened a PR to your repo to migrate to latest: https://github.com/ksdc-grantw/vite-server-bug/pull/1
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.