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

🐛 BUG: astro preview stopped working #2981

Closed
1 task
herteleo opened this issue Apr 4, 2022 · 7 comments · Fixed by #3004
Closed
1 task

🐛 BUG: astro preview stopped working #2981

herteleo opened this issue Apr 4, 2022 · 7 comments · Fixed by #3004

Comments

@herteleo
Copy link
Contributor

herteleo commented Apr 4, 2022

What version of astro are you using?

0.26.1

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

npm run preview starts without error but shows ERR_CONNECTION_REFUSED if you try to open http://localhost:3000/ in the browser.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-uy2pjg?file=package.json

Participation

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

SebasG22 commented Apr 4, 2022

  • This is failing on 1.0.0-beta.0

@SlicedSilver
Copy link

I'm also experiencing this bug (also on a mac).

What appears to be happening is that the preview command runs without any errors and immediately quits back to the terminal. I tried running the command with the --verbose flag and with the debug env variables DEBUG=astro:*,vite:* astro preview but nothing is reported.

@SlicedSilver
Copy link

case 'preview': {
try {
return await preview(config, { logging }); // this will keep running
} catch (err) {
return throwAndExit(err);
}
}

I've noticed that the preview function above is immediately resolving (on my setup) and thus not staying open. I wasn't able to see any recent changes that explain why this behaviour has changed.


A naive solution seems to be changing the code to resemble the dev function by adding a return await new Promise(() => {});. Not sure what the knock-on effects of this change would be, but it does seem to resolve the issue on my device.

case "preview": {
      try {
        await preview(config, { logging });
        return await new Promise(() => {
        });
      } catch (err) {
        return throwAndExit(err);
      }
    }

Hopefully this helps to track down the root cause.

@idrakimuhamad
Copy link

Running preview in 1.0.0-beta.2 will display below and the task stopped. I've tried running build first and the preview but its just the same.

🚀  astro  v1.0.0-beta.2 started in 2ms
  
  ┃ Local    http://localhost:3000/
  ┃ Network  use --host to expose

@hippotastic
Copy link
Contributor

hippotastic commented Apr 5, 2022

The same error happens on Windows 10 for me. Preview starts and outputs the URL, but then it exits immediately.

@karthik-srinivas
Copy link

karthik-srinivas commented Apr 5, 2022

yes this is happening for me as well

image

the process is getting terminated just after running preview in my case serve

version - "astro": "^1.0.0-beta.2"

when I tested it, version "astro": "^0.25.2" is working fine

tony-sull pushed a commit that referenced this issue Apr 6, 2022
tony-sull pushed a commit that referenced this issue Apr 6, 2022
* fix(#2981): keeps  server alive

* chore: adding changeset

* keep alive until the 'close' or 'error' event fires
@tony-sull tony-sull linked a pull request Apr 6, 2022 that will close this issue
@tony-sull
Copy link
Contributor

Thanks for all the debugging and details in this issue! Just merged #3004 with a fix

SiriousHunter pushed a commit to SiriousHunter/astro that referenced this issue Feb 3, 2023
* fix(withastro#2981): keeps  server alive

* chore: adding changeset

* keep alive until the 'close' or 'error' event fires
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants