Skip to content
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

Astro runs on :3000 port even though another app is running on the same port #4315

Closed
1 task
yxshv opened this issue Aug 14, 2022 · 8 comments · Fixed by #4509
Closed
1 task

Astro runs on :3000 port even though another app is running on the same port #4315

yxshv opened this issue Aug 14, 2022 · 8 comments · Fixed by #4509
Labels
- P2: nice to have Not breaking anything but nice to have (priority)

Comments

@yxshv
Copy link

yxshv commented Aug 14, 2022

What version of astro are you using?

1.0.1

Are you using an SSR adapter? If so, which one?

no

What package manager are you using?

pnpm

What operating system are you using?

Windows

Describe the Bug

I had a React app running on port 3000 and ran an astro app thinking that it will automatically use a different port. Bu, it didn't

Link to Minimal Reproducible Example

just run an different app on localhot:3000 and then run an astro app

Participation

  • I am willing to submit a pull request for this issue.
@bluwy
Copy link
Member

bluwy commented Aug 15, 2022

Astro's dev server uses Vite. Does this happen on a Vite app too? Also, is your React app running on http://172.0.0.1:3000 or http://[::1]:3000. The port detection depends on which hostname your React app is running vs Vite's

@FredKSchott
Copy link
Member

FredKSchott commented Aug 15, 2022

I can't reproduce. When I have something running on :3000, astro dev starts on :3001 instead. Maybe this is a Windows limitation?

@FredKSchott
Copy link
Member

@yxshv can you go into your node_modules folder and add some logging to this file? I'm curious if onError isn't being hit here on Windows.

const onError = (err: NodeJS.ErrnoException) => {
if (err.code && err.code === 'EADDRINUSE') {
if (!showedPortTakenMsg) {
info(logging, 'astro', msg.portInUse({ port }));
showedPortTakenMsg = true; // only print this once
}
port++;
return listen(); // retry
} else {
error(logging, 'astro', err.stack || err.message);
httpServer?.removeListener('error', onError);
reject(err); // reject
}
};

@FredKSchott FredKSchott added - P2: nice to have Not breaking anything but nice to have (priority) s1-small labels Aug 15, 2022
@yxshv
Copy link
Author

yxshv commented Aug 15, 2022

@FredKSchott Nope it does not.

        httpServer == null ? void 0 : httpServer.on("error", onError);
      };
      const onError = (err) => {
        console.log(err)    // +++++++++++
        if (err.code && err.code === "EADDRINUSE") {
          if (!showedPortTakenMsg) {
            console.log("port taken")    // +++++++++++
            info(logging, "astro", msg.portInUse({ port }));
            showedPortTakenMsg = true;
          }
          port++;
          return listen();
       listen();
    });
  }
  console.log("starting server");    // +++++++++
  await startServer(startServerTime);
  function closed() {
    return new Promise((resolve, reject) => {
      httpServer.addListener("close", resolve);
      httpServer.addListener("error", reject);
    });
  }

@yxshv
Copy link
Author

yxshv commented Aug 15, 2022

I thought. Lets just use a different PORT and added PORT=3001 in environment variables

and to my surprise it still ran on :3000

@bluwy
Copy link
Member

bluwy commented Aug 17, 2022

and to my surprise it still ran on :3000

I don't think we support reading from PORT.

Is this issue related to astro dev or astro preview or both? And how are you starting your other app

@yxshv
Copy link
Author

yxshv commented Aug 17, 2022

and to my surprise it still ran on :3000

I don't think we support reading from PORT.

Is this issue related to astro dev or astro preview or both? And how are you starting your other app

oh. It does not work on both dev and preview

I am starting the other react (nextjs) app with pnpm dev

@SachaG
Copy link

SachaG commented Aug 22, 2022

Same issue here:

Screen Shot 2022-08-22 at 20 22 47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants