Skip to content

fix(content): declare zod as optional peer dependency (#622)#625

Merged
harlan-zw merged 2 commits into
mainfrom
fix/content-ogimage-zod-instance
Jun 5, 2026
Merged

fix(content): declare zod as optional peer dependency (#622)#625
harlan-zw merged 2 commits into
mainfrom
fix/content-ogimage-zod-instance

Conversation

@harlan-zw

@harlan-zw harlan-zw commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

🔗 Linked issue

Resolves #622

❓ Type of change

  • 🐞 Bug fix
  • 📖 Documentation

📚 Description

Property 'ogImage' does not exist on type 'ContentCollectionItem' (regressed in v6.5.1).

Root cause: zod was a hard dependency pinned to v4, but it's only used by the Content integration (src/content.ts). That forced og-image's own zod 4 copy into the user's tree even when @nuxt/content resolved zod 3. Content builds each collection's TS type from the schema object (zod → JSON Schema via zodToJsonSchema → interface via json-schema-to-typescript-lite), and that converter only understands one zod version's internals. A foreign-instance ogImage sub-schema fails to convert, so the field drops off the generated ContentCollectionItem.

Fix: move zod to an optional peerDependency (>=3), matching the rest of the SEO ecosystem (@nuxtjs/sitemap, @nuxtjs/robots, nuxt-schema-org all do this). og-image now resolves the project's single zod instance, so defineOgImageSchema() works by default with no extra config. Kept in devDependencies for the repo's own build.

Docs reframed to show the default usage, with defineOgImageSchema({ z }) documented as a fallback for projects that have multiple zod versions installed.

Note for the reporter: the typed access path is queryCollection('content').path(...).first() (per-collection types). useContent() returns the broad cross-collection base type and may still not surface ogImage.

Resolves #622. defineOgImageSchema() built the ogImage field with og-image's
bundled zod. When that differs from the project's zod (e.g. og-image on zod 4,
@nuxt/content on zod 3), Content's per-collection type inference over the
foreign-instance schema collapses and ogImage drops off ContentCollectionItem.
Passing the project's own instance via defineOgImageSchema({ z }) keeps the
whole schema on one zod version so the field is inferred. This is the same
remedy nuxtseo-shared's own version-mismatch warning recommends.
@pkg-pr-new

pkg-pr-new Bot commented Jun 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nuxt-og-image@625

commit: 534c90f

The real fix for #622. zod was a hard dependency pinned to v4, so og-image
forced its own zod copy into the user's tree even when @nuxt/content resolved
zod 3. Content builds collection types from the schema object, and a foreign
zod-instance ogImage field fails to convert, dropping it from the generated
ContentCollectionItem.

Move zod to an optional peer dependency (>=3), matching @nuxtjs/sitemap,
@nuxtjs/robots and nuxt-schema-org. og-image now resolves the project's own
zod instance, so defineOgImageSchema() works by default. Reframe the docs to
show the default usage with { z } as a fallback for multi-version trees, and
keep it in devDependencies for the repo's own build.
@harlan-zw harlan-zw changed the title docs(content): pass user zod instance to defineOgImageSchema fix(content): declare zod as optional peer dependency (#622) Jun 5, 2026
@harlan-zw harlan-zw merged commit 75bbb05 into main Jun 5, 2026
11 checks passed
@harlan-zw harlan-zw deleted the fix/content-ogimage-zod-instance branch June 5, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Property 'ogImage' does not exist on type 'ContentCollectionItem'

1 participant