timlrx / contentlayer2

Contentlayer turns your content into data - making it super easy to import MD(X) and CMS content in your app
https://contentlayer.dev
MIT License
153 stars 11 forks source link

TypeError: Cannot read properties of undefined (reading 'split') after configuring ppr experimental feature in nextjs 15 #33

Closed tonyabracadabra closed 1 month ago

tonyabracadabra commented 1 month ago
⨯ TypeError: Cannot read properties of undefined (reading 'split')
    at JSON.parse (<anonymous>)
    at JSON.parse (<anonymous>)
    at JSON.parse (<anonymous>)
    at JSON.parse (<anonymous>)
    at JSON.parse (<anonymous>)
    at JSON.parse (<anonymous>)
digest: "3168819825"

Got the error above on

"next": "15.0.0-canary.76"
"react": "19.0.0-rc-512b09b2-20240718",
"contentlayer2": "^0.5.0",
import { useMDXComponent } from "next-contentlayer2/hooks";
import * as React from "react";

import { MdxCard } from "@/components/blog/mdx-card";
import { Callout } from "@/components/blog/callout";
import { cn } from "@/lib/utils";
import ClientTweetCard from "./client-tweet-card";
import Image from "next/image";

const components = {
  h1: ({ className, ...props }: any) => (
    <h1
      className={cn(
        "mt-2 scroll-m-20 text-4xl font-bold tracking-tight",
        className
      )}
      {...props}
    />
  ),
  h2: ({ className, ...props }: any) => (
    <h2
      className={cn(
        "mt-10 scroll-m-20 border-b pb-1 text-2xl font-semibold tracking-tight first:mt-0",
        className
      )}
      {...props}
    />
  ),
};

interface MdxProps {
  code: string;
}

export function Mdx({ code }: MdxProps) {
  const Content = useMDXComponent(code);

  return (
    <div className="mdx">
      <Content components={components} />
    </div>
  );
}

I think the problem is caused by configuring

const nextConfig = {
  experimental: {
    ppr: "incremental",
}
...

in next.config.js

timlrx commented 1 month ago

It works without ppr?

tonyabracadabra commented 1 month ago

It works without ppr?

yea it works without ppr

tonyabracadabra commented 1 month ago

It works without ppr?

Hey Timothy did you have chance to replicate the error? Since nextjs 15 is still in canary, do you think this is a problem that is fixable on contentlayer side?

timlrx commented 1 month ago

Yes I get the error as well on a simple example - https://stackblitz.com/edit/github-ekmxur-ba82kk?file=next.config.js,package.json,tsconfig.json

Generated 3 documents in .contentlayer
 ✓ Compiled / in 5.7s (653 modules)
 ⨯ TypeError: Cannot read properties of undefined (reading 'stack')
    at AsyncLocalStorage.run (node:async_hooks:18:3866)
    at AsyncLocalStorage.run (node:async_hooks:18:3866)
digest: "2227156382"
 ⨯ TypeError: Cannot read properties of undefined (reading 'stack')
    at AsyncLocalStorage.run (node:async_hooks:18:3866)
    at AsyncLocalStorage.run (node:async_hooks:18:3866)

It's strange since experimental_ppr is not even set for the route, so my guess it is a framework issue. Given that there are a lot of existing open issues on ppr, I will let next.js fix it before trying it out.

tonyabracadabra commented 1 month ago

Yes I get the error as well on a simple example - https://stackblitz.com/edit/github-ekmxur-ba82kk?file=next.config.js,package.json,tsconfig.json

Generated 3 documents in .contentlayer
 ✓ Compiled / in 5.7s (653 modules)
 ⨯ TypeError: Cannot read properties of undefined (reading 'stack')
    at AsyncLocalStorage.run (node:async_hooks:18:3866)
    at AsyncLocalStorage.run (node:async_hooks:18:3866)
digest: "2227156382"
 ⨯ TypeError: Cannot read properties of undefined (reading 'stack')
    at AsyncLocalStorage.run (node:async_hooks:18:3866)
    at AsyncLocalStorage.run (node:async_hooks:18:3866)

It's strange since experimental_ppr is not even set for the route, so my guess it is a framework issue. Given that there are a lot of existing open issues on ppr, I will let next.js fix it before trying it out.

Thanks!

tonyabracadabra commented 1 month ago

The error is gone on the latest nextjs canary