withastro / astro

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

Middleware code is executed during build #12495

Closed rktyt closed 3 hours ago

rktyt commented 11 hours ago

Astro Info

Astro                    v4.16.14
Node                     v20.15.0
System                   Linux (arm64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/node
Integrations             @astrojs/react

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

No response

Describe the Bug

In v4.16.13, the build passed without any errors, but in v4.16.14 the build started to fail. It looks like the build is "executing" the middleware code.

What's the expected result?

There are no errors in the build. The build is expected to only be transpiled.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-patrsd?file=src%2Fmiddleware%2Findex.ts

Please run npm run build.

Participation

ematipico commented 8 hours ago

It's possible you missed that part, but that's expected. We explain it right at the beginning of our docs: https://docs.astro.build/en/guides/middleware/#_top

rktyt commented 7 hours ago

@ematipico Document says "all prerendered pages". If the setting is output: 'server', it is on-demand, so it shouldn't be executed, right?


UPDATES: I understand if there is at least one prerendered page, but if there is none, why is it executed at build time?