withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.81k stars 2.49k forks source link

`.env` Hot Reloading Error (Astro v5 Beta) #12107

Closed neelsudhakaran closed 1 month ago

neelsudhakaran commented 1 month ago

Astro Info

Astro                    v5.0.0-beta.3
Node                     v20.17.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When modifying a .env file while the dev server is running, a Vite error is logged to the console.

[ERROR] [vite] Error: cannot print server URLs before server.listen is called.

Sometimes (I can't tell if it's when you make multiple saves in rapid succession or something else), you also get the following Node error thrown.

(node:84966) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unhandledRejection listeners added to [process]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)

As far as I can tell (and I'm still using environment variables the old way) the environment variables, both with the PUBLIC_ prefix and without, still work.

What's the expected result?

I don't think these warnings, if true, are supposed to print.

Link to Minimal Reproducible Example

https://github.com/neelsudhakaran/astro-server-listen-error

Participation

ematipico commented 1 month ago

@neelsudhakaran your reproduction doesn't have an .env file, can you add it?

github-actions[bot] commented 1 month ago

Hello @neelsudhakaran. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.

neelsudhakaran commented 1 month ago

Sorry about that @ematipico! I added the .env to the repository. Any edits to the file (or even just saving it) brings up that error for me.

ascorbic commented 1 month ago

Fixed in https://github.com/withastro/astro/pull/12127

neelsudhakaran commented 1 month ago

It was really interesting to read about the fix—thank you so much by the way!