keystatic icon indicating copy to clipboard operation
keystatic copied to clipboard

Unclear error message if <collection>.format.contentField doesn't exist

Open moniquevincent opened this issue 1 year ago • 0 comments

Update: I realized this error was caused because I deleted schema.content but still had format.contentField = "content". Perhaps a targeted error could be thrown, along the lines of

throw new ConfigurationError(
  `Collection "${collectionName}" is misconfigured:\n`
  + `format.contentField is "${format.contentField}" but there is no such field in the schema property.\n`
  + `Try adding\n`
  + `  "${format.contentField}": fields.markdoc(),\n`
  + `to the schema.`
)

I have a simple Next.js project (it's just a static site: moniquevincent.com). I'm excited about adding Keystatic—it seems to be exactly what I need!

I followed the guide for integrating Keystatic into an existing Next.js project—except I made one change: I removed the default content markdoc field from the default posts collection:

import { collection, config, fields } from "@keystatic/core";

export default config({
  storage: {
    kind: "local",
  },
  collections: {
    posts: collection({
      label: "Posts",
      slugField: "title",
      path: "content/posts/*",
      format: { contentField: "content" },
      schema: {
        title: fields.slug({ name: { label: "Title" } }),
-       content: fields.markdoc({ label: "Content" }),
      },
    }),
  },
});

Upon loading http://127.0.0.1:3000/keystatic/, I see the following error in a Next.js error popup:

TypeError: undefined is not an object (evaluating 'schema.kind')

The callstack just says "Native code" (i.e., React internals), but this is also logged in the console:

The above error occurred in the <NotFoundErrorBoundary> component:

LocalAppShellProvider
AppShell
PageInner
div
ProviderWrapper
$ea8dcbcb9ea1b556$export$323e4fc2fa4753fb
$f57aed4a881a3485$export$178405afcd8c5eb
$18f2051aff69b9bf$export$a54013f0d02a8f82
BreakpointProvider
KeystarProvider
Provider
RouterProvider
RedirectToLoopback
ClientOnly
Keystatic
Page
Layout (Server)
InnerLayoutRouter
Component@
RedirectBoundary
Component@
NotFoundBoundary
LoadingBoundary
ErrorBoundary
Component@
ScrollAndFocusHandler
RenderFromTemplateContext
OuterLayoutRouter
body
html
AdminLayout (Server)
InnerLayoutRouter
Component@
RedirectBoundary
Component@
NotFoundBoundary
LoadingBoundary
ErrorBoundary
Component@
ScrollAndFocusHandler
RenderFromTemplateContext
OuterLayoutRouter
Component@
RedirectBoundary
Component@
NotFoundBoundary
DevRootNotFoundBoundary
PureComponent@
HotReload
Router
Component@
ErrorBoundary
AppRouter
ServerRoot
Root

As it happens, I probably do want that content field...so I'm able to proceed. But the error was still unexpected.

Thanks!

cc @GiacoCorsiglia

moniquevincent avatar Sep 28 '24 18:09 moniquevincent