-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Astro 5.1.1: Cannot destructure property 'type' of 'lookupMap[collection]' as it is undefined #12885
Comments
Hi. I can't reproduce it using your example. First it fails because it's referencing an invalid tag, but when I fix that it doesn't give an error. Can you check it and try again. Also ensure you're using |
Hello @shockch4rge. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
Hi, I've updated to 5.1.2 and regenerated the |
OK, thanks for the update. I'll close this. |
i also faced this issue recently with Astro v5.1.2 or v5.1.3 (i don't remember whether I upgraded before the issue happened or after), but now cannot reproduce it if i recall correctly i got around it by first adding a new collection (the collection loader just return hardcoded array of entries), running the server and only then referencing this new collection from another one so I assume it is something related to a race condition discussed in #12680 since both are about content collections and are tricky to catch |
I'm also having the exact same issue but with v5.1.5. I tried to repro it on stackblitz but couldn't get it to happen and I tried the workaround suggested in #12680 and it fixed it. Though I'm not sure if it's actually fixed as I haven't tried to generate anything from the content collection yet. |
import { glob } from "astro/loaders";
import { defineCollection, reference, z } from "astro:content";
const blog = defineCollection({
loader: glob({ pattern: "**/[^_]*.md", base: "./src/data/blog" }),
schema: ({ image }) =>
z.object({
author: z.string().default(SITE.author),
pubDatetime: z.date(),
modDatetime: z.date().optional().nullable(),
title: z.string(),
slug: z.string().optional().nullable(),
featured: z.boolean().optional(),
draft: z.boolean().optional(),
tags: z.array(z.string()).default(["others"]),
ogImage: image()
.refine(img => img.width >= 1200 && img.height >= 630, {
message: "OpenGraph image must be at least 1200 X 630 pixels!",
})
.or(z.string())
.optional(),
description: z.string(),
canonicalURL: z.string().optional(),
editPost: z
.object({
disabled: z.boolean().optional(),
url: z.string().optional(),
text: z.string().optional(),
appendFilePath: z.boolean().optional(),
})
.optional(),
}),
});
const columns = defineCollection({
loader: glob({ pattern: "**/[^_]*.json", base: "./src/data/columns" }),
schema: z.object({
slug: z.string(),
title: z.string(),
description: z.string(),
createDatetime: z.string().date(),
status: z.string(),
}),
});
export const collections = { blog, columns };
import { glob } from "astro/loaders";
import { defineCollection, reference, z } from "astro:content";
const blog = defineCollection({
loader: glob({ pattern: "**/[^_]*.md", base: "./src/data/blog" }),
schema: ({ image }) =>
z.object({
author: z.string().default(SITE.author),
+ column: reference('column').optional().nullable(),
pubDatetime: z.date(),
modDatetime: z.date().optional().nullable(),
title: z.string(),
slug: z.string().optional().nullable(),
featured: z.boolean().optional(),
draft: z.boolean().optional(),
tags: z.array(z.string()).default(["others"]),
ogImage: image()
.refine(img => img.width >= 1200 && img.height >= 630, {
message: "OpenGraph image must be at least 1200 X 630 pixels!",
})
.or(z.string())
.optional(),
description: z.string(),
canonicalURL: z.string().optional(),
editPost: z
.object({
disabled: z.boolean().optional(),
url: z.string().optional(),
text: z.string().optional(),
appendFilePath: z.boolean().optional(),
})
.optional(),
}),
});
const columns = defineCollection({
loader: glob({ pattern: "**/[^_]*.json", base: "./src/data/columns" }),
schema: z.object({
slug: z.string(),
title: z.string(),
description: z.string(),
createDatetime: z.string().date(),
status: z.string(),
}),
});
export const collections = { blog, columns };
|
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
Collection references cannot be defined as an array in the content collection schema. Tested with the file loader; haven't seen results with the glob loader yet. Restart the server in the stackblitz and the error should show.
Submitted issue from my own findings and this reply here: #12616 (comment)
What's the expected result?
You should be able to define collection reference arrays, as seen in this example from the astro docs: https://docs.astro.build/en/guides/content-collections/#defining-collection-references
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-rzbnajjs?file=src%2Fcontent.config.ts
Participation
The text was updated successfully, but these errors were encountered: