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

[WARN] Astro.request.headers is not available in "static" output mode. #10212

Closed
1 task done
mrcnski opened this issue Feb 23, 2024 · 18 comments
Closed
1 task done

[WARN] Astro.request.headers is not available in "static" output mode. #10212

mrcnski opened this issue Feb 23, 2024 · 18 comments
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)

Comments

@mrcnski
Copy link

mrcnski commented Feb 23, 2024

Astro Info

Astro                    v4.4.3
Node                     v21.5.0
System                   macOS (arm64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

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

No response

Describe the Bug

Since upgrading to Astro 4.4.3 I'm getting this warning in the console:

[WARN] `Astro.request.headers` is not available in "static" output mode. To enable header access: set `output: "server"` or `output: "hybrid"` in your config file.

What's the expected result?

I was not getting this warning on Astro 4.3.7.

I'm not doing anything with headers AFAIK, but it would be nice to have a trace to know where this warning is coming from.

I tried for some time but I'm having trouble reproducing this on Stackblitz or in a fresh project. As mentioned above, a trace would be nice. My project is simple, my only dependencies are Astro and Typescript.

Link to Minimal Reproducible Example

https://stackblitz.com/see-above

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Feb 23, 2024
@Reyno-Skeps
Copy link

Can confirm, running into the same issue right now.

@Princesseuh
Copy link
Member

Will be fixed by #10196, sorry for the inconvenience. It's a bug with i18n in particular

@mrcnski
Copy link
Author

mrcnski commented Feb 23, 2024

Awesome! Sorry, I searched existing issues but didn't think to search PRs.

@matthewp matthewp added - P4: important Violate documented behavior or significantly impacts performance (priority) and removed needs triage Issue needs to be triaged labels Feb 23, 2024
@bluwy
Copy link
Member

bluwy commented Feb 26, 2024

#10196 has been merged

@bluwy bluwy closed this as completed Feb 26, 2024
@mrcnski
Copy link
Author

mrcnski commented Feb 27, 2024

I've confirmed that this has been fixed as of 4.4.5, thanks everybody.

@eitelkrauss
Copy link

I just upgraded to 4.5.9 and I'm running into this issue. The warning is only for my prerendered pages. I have output: 'server'

@boredland
Copy link

can confirm this still is a problem with hybrid, i18n and such a .astro file:

---
import { getHeadersLocale } from '../utils/headersLocale'

const locale = getHeadersLocale(Astro.request.headers.get('accept-language') ?? 'en')
  
return Astro.redirect(`/${locale}`)
---

@matthewp
Copy link
Contributor

This is intentional. You can't read headers in a static page. We do this on purpose so that you don't rely on behavior that will lead to build-time and run-time differences.

@eitelkrauss
Copy link

eitelkrauss commented Mar 27, 2024

@matthewp I'm not reading any headers though.

EDIT: I was reading headers.. sorry

@daolanfler
Copy link

---
import ThemeToggle from "./ThemeToggle";
const cookie = Astro.cookies.get("theme");

export const prerender = false;
---

<ThemeToggle themeCookie={cookie?.value} client:load />

I have a ThemeToggle component like this, this component is accessing cookie in headers. And my astro.config.mjs is output: hybrid. This component runs on server instead of client as I've specified prerender=false, but I still get the warning, and I thinks it's ok to access headers in this situation...

@rottmann
Copy link

rottmann commented May 3, 2024

Hint: this error occurs on symbolic linked files too, even if prerender is set to false.

@xabru
Copy link

xabru commented Oct 12, 2024

I encountered the same warning again in the latest update "4.16.1." I had to downgrade to "4.16.0" to make the warning disappear in a project created from scratch using bun create astro.

@jahands
Copy link

jahands commented Oct 12, 2024

Same here, running Astro on Cloudflare Workers. Just upgraded and started getting this warning. I also have an endpoint that started failing with this error on the server side:

(error) 12:28:48 [ERROR] TypeError: Can't modify immutable headers.
    at setOriginHeader (_worker.js:163:25960)
    at RenderContext.create (_worker.js:165:3228)
    at async bn.render (_worker.js:180:186)
    at async Object.fetch (_worker.js:180:5208)

(not sure if related or if this is a separate issue.)
edit: separate issue: #12201

@yoyo837
Copy link
Contributor

yoyo837 commented Nov 24, 2024

Same warning in 4.16.14

@Mistwell
Copy link

Same warning in "astro": "^4.16.13",
just have 2 static mainpages with i18n

@ematipico
Copy link
Member

@Mistwell update to the latest, this was fixed

@yoyo837
Copy link
Contributor

yoyo837 commented Nov 27, 2024

4.16.15 fixed this.

@vv3rd
Copy link

vv3rd commented Dec 13, 2024

Encountered this issue on 4.16.15 when Astro.rewrite is used.
To reproduce create src/pages/[your_locale_of_choice]/test.astro with

---
return Astro.rewrite('/anohter-page')
---

Warning goes away if you pass new instance of Request

---
return Astro.rewrite(new Request(new URL('/another-page', Astro.url.origin)));
---

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)
Projects
None yet
Development

No branches or pull requests