-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
Docusaurus chooses port 3000 even if it is busy #8202
Comments
I've discovered the same recently. It doesn't seem to reproduce with two Docusaurus servers—only when one port is running something else. |
@Josh-Cena Correct, the explanation for this is that Docusaurus does |
😄 As far as I remember this code was copied from CRA in #3005 and we use the detect-port library: https://github.com/node-modules/detect-port It seems to use a similar approach of attempting to create the server: https://github.com/node-modules/detect-port/blob/master/lib/detect-port.js#L101 Maybe we don't pass it the correct params? Or maybe it's worth opening a bug in that lib directly so that the whole ecosystem benefits from a fix? If anyone wants to investigate if detect-port has a bug or not that would be convenient :) |
Dug deper:
I found that if Docusaurus switches to |
Thanks 💯 If only someone could just create a shared package that works for everyone 😅 looks like CRA is using detect-port-alt now (published by Dan Abramov, no fork repo linked 😓 ). That probably was for a good reason. Interesting related CRA issues:
|
Docusaurus defaults to binding to the loopback interface, which does not conflict with another process attempting to listening on all interfaces. The dev tool will detect a conflict in this case if the host is set to $ npx docusaurus start -h 0.0.0.0
✔ [WARNING] Something is already running on port 3000. Probably:
`node server.js` (pid 44444) in "/private/tmp" Perhaps the default should be changed? Note that |
Here's what works for me now: npm script:
and have detect-port installed as a dev dependency Not sure whether this will work on Windows with the expansion. I imagine that upgrading to latest detect-port could fix it? Although I see |
PR submitted (#8202) I will await a review. |
Have you read the Contributing Guidelines on issues?
Prerequisites
npm run clear
oryarn clear
command.rm -rf node_modules yarn.lock package-lock.json
and re-installing packages.Description
On macOS, consider the following script
server.js
:Run it using
node server.js
.Then start a Docusaurus project (running on v2.1.0 in my case). The documentation server will start on port 3000, although it is busy. If you then open Docusaurus in Chrome:
it opens my server.
however, if I use curl, I get the docusaurus page!
If my server passes a host:
then Docusaurus will correctly identify that the port is busy and asks if I want to choose another port. Nonetheless I see it as a bug in Docusaurus or one of it's dependencies.
Possible solution
Although used by less people, this logic for finding a free port works now in Remotion without bug reports coming in: https://github.com/remotion-dev/remotion/blob/main/packages/renderer/src/get-port.ts
I am happy to chat on Discord how to investigate it together!
Reproducible demo
No response
Steps to reproduce
As above
Expected behavior
Busy port detection kicks in and asks if a different port should be used
Actual behavior
Server gets started and a conflict is created
Your environment
Self-service
The text was updated successfully, but these errors were encountered: