-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Cannot access 'getCollection' before initialization when running build
#8972
Comments
edit: minimal https://stackblitz.com/edit/starlight-getcollection I'm having the same issue, works on dev but can't build. Tried to reproduce without Starlight but couldn't. And this work perfectly on official Astro docs, as it is from I I went as far as adding editing Starlight source code (instead of override) but no difference, I guess any override will give the same result, I've tried with head and banner: Steps on a new Starlight Project:
components: {
Footer: './src/components/overrides/test.astro',
},
---
import { sum } from 'src/pages/thisFile';
sum();
---
import { getCollection } from 'astro:content';
const pages= await getCollection('docs');
console.log(pages);
export function sum() {
1 - 1
} The very same function works when called from a file outside example:
Hope this helps to triage |
Hello, unfortunately this is a limitation of how Astro components work. The |
I wonder how withastro/docs is doing it, the code seems to have a very similar implementation for OpenGraph, just importing it from When I attempt to do the same on my project, it fails for the same reason as this issue. |
for context, this is a PR from Astro Docs migration to Starlight, it's in active development as of now and in the future this hack may not be needed anymore. 00 hack: withastro/docs@030073f thanks Delucis! |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
I am generating a open graph image with
src/pages/open-graph/[...path].ts
:When running
bun run build
, I get the following output:What's the expected result?
bun run astro dev
generates the images correctly.bun run build
should also, I am unsure whygetCollection
would not be available/uninitialized at build time?Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-2zqutw
Participation
The text was updated successfully, but these errors were encountered: