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

Astro 5.1.1: Cannot destructure property 'type' of 'lookupMap[collection]' as it is undefined #12885

Open
1 task
shockch4rge opened this issue Jan 3, 2025 · 7 comments · May be fixed by #12990
Open
1 task
Labels
feat: content layer Related to the Content Layer feature (scope)

Comments

@shockch4rge
Copy link

shockch4rge commented Jan 3, 2025

Astro Info

Astro                    v5.1.1
Node                     v22.11.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             @astrojs/tailwind
                         @astrojs/mdx

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

  • 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 Jan 3, 2025
@ascorbic
Copy link
Contributor

ascorbic commented Jan 3, 2025

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 5.1.2 in your site.

@ascorbic ascorbic added needs repro Issue needs a reproduction and removed needs triage Issue needs to be triaged labels Jan 3, 2025
Copy link
Contributor

github-actions bot commented Jan 3, 2025

Hello @shockch4rge. 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.

@shockch4rge
Copy link
Author

shockch4rge commented Jan 3, 2025

Hi, I've updated to 5.1.2 and regenerated the .astro folder at the same time, and my issue seems to have gone away, but the 5.1.2 changelog doesn't seem to mention such a fix.

@ascorbic
Copy link
Contributor

ascorbic commented Jan 6, 2025

OK, thanks for the update. I'll close this.

@ascorbic ascorbic closed this as not planned Won't fix, can't repro, duplicate, stale Jan 6, 2025
@vorant94
Copy link

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

@ProfDoof
Copy link

ProfDoof commented Jan 10, 2025

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.

@PassionZale
Copy link

image

  1. Define BlogCollection and ColumnCollection
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 };
  1. Run npm run dev

  2. Run Control+C stop server

  3. Add reference('column') to BlogCollection

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 };
  1. Run npm run dev get error:

image

  1. Delete .astro folder, Run npm run dev again, can not faced this issue.

@ascorbic ascorbic linked a pull request Jan 15, 2025 that will close this issue
@ascorbic ascorbic reopened this Jan 15, 2025
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 15, 2025
@ascorbic ascorbic added feat: content layer Related to the Content Layer feature (scope) and removed needs repro Issue needs a reproduction needs triage Issue needs to be triaged labels Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: content layer Related to the Content Layer feature (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants