Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 bug: passing frontMatterType is causing crash in nextJS #111

Open
souravdasslg opened this issue May 8, 2024 · 1 comment
Open

Comments

@souravdasslg
Copy link

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'
}
@souporserious
Copy link
Owner

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.

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

No branches or pull requests

2 participants