nx icon indicating copy to clipboard operation
nx copied to clipboard

Vite does not release ports when the server is stopped (v20.0.0)

Open ksdc-grantw opened this issue 1 year ago • 4 comments

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

  1. Checkout https://github.com/ksdc-grantw/vite-server-bug and run npm install This is a fresh workspace generated by npx create-nx-workspace@latest
  2. Run the app, nx serve vite-app
  3. Stop the app
  4. 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.

ksdc-grantw avatar Oct 07 '24 09:10 ksdc-grantw

Same issue. Pressing CTRL+C to stop the server does not stop the server.

brianlagunas avatar Oct 07 '24 16:10 brianlagunas

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>

llong2195 avatar Oct 09 '24 02:10 llong2195

I am also facing same issue in nx 19.8.4. I have to manully kill the processes

manpreet-compro avatar Oct 10 '24 05:10 manpreet-compro

Same issue when using rspack

dennyak47 avatar Oct 17 '24 07:10 dennyak47

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

Coly010 avatar Oct 28 '24 16:10 Coly010

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.

github-actions[bot] avatar Nov 28 '24 00:11 github-actions[bot]