[cms-fs] Error converting file to document - Netlify VIsual Editor stackbit

sitename: https://main--telnyxdotcom-docs.netlify.app

I was following Netlify docs for setting up the visual editor and it’s failing on sitemap generation with:

warn: [cms-fs] Error converting file to document: voice/webrtc/quickstart/index.mdx
warn: [cms-fs] Error converting file to document: voice/webrtc/reactsdk/index.mdx
info: [content-store] → Loaded git content source data (project: e3e2a9bf): 1 model, 0 documents and 352 assets
info: Server started. Forwarding requests to: localhost:3000
info: ⚡ Open http://localhost:8090/_stackbit in your browser

ref: Content Modeling | Visual Editing Docs

logs: Netlify Create

My setup with stackbit.config.js

const stackbitConfig = {
  stackbitVersion: "~0.6.0",
  ssgName: "custom",
  nodeVersion: "20",
  contentSources: [
    new GitContentSource({
      rootPath: __dirname,
      contentDirs: ["docs"],

      models: [
        {
          name: "page",
          type: "page",
          filePath: "docs/{slug}.mdx",
          fields: [
            {
              name: "title",
              label: "SEO Title",
              type: "string",
              required: true,
            },
            {
              name: "markdown_content",
              label: "Body",
              type: "markdown",
              required: true,
            },
          ],
        },
      ],
      assetsConfig: {
        referenceType: "static",
        staticDir: "static",
        uploadDir: "img",
        publicPath: "/assets",
      },
    }),
  ],

  devCommand: "npm run dev -- --port {PORT} --host {HOSTNAME}",
};

export default stackbitConfig;

It’s failing on both “Netlify Create” and “Local development”

Yes I’m also hitting this. Even if I take the site down to a single page:

info: [content-store] Initializing content source: git (project: NUMBER)
warn: [cms-fs] Error converting file to document: _index.md
info: [content-store] → Loaded git content source data (project: NUMBER): 1 model, 0 documents and 7 assets
1 Like

I’ve asked the devs about this. Will let you know once we have more info.

Hello @hrishikesh,

any updates on this?

I was able to find a solution. In the end the @stackbit/cms-git was expecting a field that was not included in the documentation pages: models type. I read the source code and provided the configuration expected by the package along with updating all my target files to include the type field. Could Netlify please update the docs on the above?

Here’s my final config file:

import { defineStackbitConfig, StackbitConfig } from "@stackbit/types";
import { GitContentSource } from "@stackbit/cms-git";

const models: StackbitConfig["models"] = {
  page: {
    type: "page", // this is the field that was missing
    urlPath: "/{slug}",
    filePath: "{slug}/index.mdx",
    fields: [
      {
        name: "title",
        label: "SEO Title",
        type: "string",
        required: true,
      },
      {
        name: "description",
        label: "SEO Description",
        type: "string",
        required: false,
      },
      {
        name: "keywords",
        label: "SEO Keywords",
        type: "list",
        items: { type: "string" },
        required: false,
      },
      {
        name: "unlisted",
        label: "SEO Unlisted",
        type: "boolean",
        required: false,
        controlType: "button-group",
      },
      {
        name: "markdown_content",
        label: "Body",
        type: "markdown",
        required: true,
      },
    ],
  },
};

export default defineStackbitConfig({
  stackbitVersion: "~0.6.0",
  ssgName: "custom",
  nodeVersion: "20",
  models,
  contentSources: [
    new GitContentSource({
      rootPath: __dirname,
      contentDirs: ["docs"],
      models: [{ ...models.page, name: "page" }],
      assetsConfig: {
        referenceType: "static",
        staticDir: "static",
        uploadDir: "img",
        publicPath: "/assets",
      },
    }),
  ],

  devCommand: "npm run dev -- --port {PORT} --host {HOSTNAME}",
});

I had to provide the models config in the root of the stackbit config object and inside of GitContentSource for the project setup to work. Here’s a file example (file.mdx):

---
type: page
title: Overview
description: Welcome to Telnyx! This quickstart is designed to get you started
  right away with creating your account and using the developer portal to do
  some common actions.
---

# Guides overview

Learn the basics of our developer platform

## Get started

To start building with Telnyx, you’ll need to sign up for an account on our Mission Control Portal, as well as perform a few tasks below, including: buying a phone number, creating a SIP Connection, creating an Outbound Voice Profile, and obtaining your API Keys. 

Then the CLI ran normally

info: Running Stackbit Dev (CLI v0.3.90)
info: Site directory: <redacted>
info: localId: <redacted>
info: Content sources found: git (project: <redacted>, version: 1.0.6)
info: Using Content Source Interface
info: [content-store] Initializing content source: git (project: <redacted>)
info: [content-store] → Loaded git content source data (project: <redacted>): 1 model, 214 documents and 373 assets
info: Server started. Forwarding requests to: localhost:3000
info: ⚡ Open http://localhost:8090/_stackbit in your browser

Thanks @dottelnyx . Yes Stackbit declares three types: page, object, and data. But then in your markdown you need to declare a type, but this is not the type in stackbit, this is the model NAME in Stackbit. So if you have a model called Home with a type of page, in your home.md you need to declare a type of home. type=“Home” and it must match the name field. This is undocumented.

hi, thanks for writing back in with your solution! We appreciate the effort you made in documenting this. Cheers!