π bug: passing frontMatterType is causing crash in nextJS
souravdasslg opened this issue Β· comments
What exactly happened?
I started using MDXTS a couple of days ago and this is working fine, but right now I got hit with a bug. On passing frontMatter type causing a crash.
import { createSource } from "mdxts";
type FrontMatter = {
title: string
seoTitle: string
description: string
abstract: string
publishedOn: Date
keywords: string
isPublished: boolean
}
export const getBlogPaths = createSource<{ frontMatter: FrontMatter}>("../_mdx/*.mdx");
The above code will work fine if I don't pass the frontMatter type.
export const getBlogPaths = createSource("../_mdx/*.mdx");
Error shown in console
TypeError: Cannot convert undefined or null to object
at Function.entries (<anonymous>)
at formatFrontMatterValue (webpack-internal:///(rsc)/./node_modules/mdxts/dist/src/index.js:346:27)
at eval (webpack-internal:///(rsc)/./node_modules/mdxts/dist/src/index.js:80:35)
at Array.map (<anonymous>)
at eval (webpack-internal:///(rsc)/./node_modules/mdxts/dist/src/index.js:79:62)
at Array.forEach (<anonymous>)
at createSource (webpack-internal:///(rsc)/./node_modules/mdxts/dist/src/index.js:78:23)
at eval (webpack-internal:///(rsc)/./app/utils/getBlogPaths.ts:10:73) {
type: 'TypeError'
}
I'm not quite sure why this is erroring since all of the front matter fields seem ok π€. My guess is the file being type-checked has some unexpected data. I updated the formatter here to better account for undefined
and null
values. Please update to 0.17.0 to try and fix, if you're still experiencing issues and can reproduce in a public repository I'm happy to take a closer look.