Skip to content

The preview mode doesn't correctly inform the user about port occupied. #6519

@dohooo

Description

@dohooo

Describe the bug

First of all, I want to thank the author team for making such an amazing work!~

When I had a 5000 port service, vite preview did not detect the port occupation and executed the service as usual, but the service could not respond normally.

It took me a whole afternoon to find this problem. Later, I found that a function of MAC OS occupied port 5000, but Vite didn't give me the corresponding prompt, so I couldn't access Preview normally,

I am aware of this PR(#6300) and will be modifying ports 5000 to 4000, but I don't think this is a good solution to this problem. I am a newbie and I am sure there are many other newbies who have spent some time here as I have.

I try to use the "net" modules to check for port occupancy, and I find it works fine. But I can't say why. I would like to submit PR if possible.

Reproduction

https://github.com/dohooo/vite-reproduction

yarn

yarn anotherServer
yarn preview

I think it should give me a corresponding prompt when I do yarn preview.

System Info

System:
    OS: macOS 12.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 30.22 GB / 64.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.18.1 - ~/.nvm/versions/node/v14.18.1/bin/node
    Yarn: 1.22.17 - /opt/homebrew/bin/yarn
    npm: 6.14.15 - ~/.nvm/versions/node/v14.18.1/bin/npm
  Browsers:
    Chrome: 97.0.4692.71
    Safari: 15.2
  npmPackages:
    @vitejs/plugin-react: ^1.0.7 => 1.1.4 
    vite: ^2.7.2 => 2.8.0-beta.2

Used Package Manager

yarn

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions