Skip to content

failure (and poor error message) if fields is missing from defineDocument #268

Closed

Description

@timfee

Hi there,

Just came across a discrepancy with the docs vs. functionality.

I was creating a singleton Homepage document:

export const Home = defineDocumentType(() => ({
  name: 'Home',
  isSingleton: true,
  filePathPattern: `index.mdx`,
}))

But got a pretty cryptic error when spinning it up, prefaced by This error shouldn't have happened. Please consider opening a GitHub issue with the stack trace below here: https://github.com/contentlayerdev/contentlayer/issues.

The documentation doesn't say that fields is required:

Screen Shot 2022-07-12 at 14 18 14@2x

However, when I changed contentlayer.config.js to .ts, it complained that fields was missing, and I was able to resolve the issue pretty trivially:

export const Home = defineDocumentType(() => ({
  name: 'Home',
  isSingleton: true,
  filePathPattern: `index.mdx`,
  fields: []
}))

Not sure if the documentation (where it's optional) is the intended behavior, or if the code is functioning correctly and friendlier errors/clearer docs would be helpful, but sharing the discrepancy :)

Activity

  1. added this to the Next milestone on Aug 1, 2022
  2. schickling commented on Aug 5, 2022

    @schickling
    Collaborator

    This should be addressed with the 0.2.7 release. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions