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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does not yet support Next.js Version 13 #307
Comments
Thanks for the report. We haven't had the opportunity to test it out with v13 yet, but we'll take a look at this soon! |
I'm just going to piggyback off of this issue rather than creating a new one (can if the author prefers). There seems to be a separate issue when server/static rendering with Next 13. export default async function Post(props: Props) {
const source = await serialize("Some **mdx**");
return (
<div>
<MDXRemote {...source} />
</div>
);
} will result in the following error
However, wrapping the component to force it to client render like so "use client";
import { MDXRemote, MDXRemoteProps } from "next-mdx-remote";
export default function MDXRemoteWrapper(props: MDXRemoteProps) {
return <MDXRemote {...props} />;
} It seems to "solve" the issue. I'm too tired to look into it anymore tonight but may poke around tomorrow if no one else is looking into it. But it seems like wrapping it like this is needed without some reorganization of the project, so the MDXRemote component gets loaded in with the "use client" directive. |
Hey all, In addition to the above, I'm seeing the following build errors while trying to
This only happens when we try and enable the Thought we'd keep all the Next 13 issues in the same place if possible so just tacking on here. |
Same issue here. |
If anyone is willing to make a codesandbox or minimal reproduction repo, that would be very helpful! |
Here it is: test-app Thank you! |
Just a small note here - we are aware on the nextjs team that the app directory doesn't yet support mdx-remote. We have it on our roadmap to address this, but aren't quite there yet. We're still working on fixing critical bugs and stabilizing it right now, as it's still beta. I'll drop updates here when we start working on this! |
For anyone else who is blocked by this, you can create a wrapper component (outside of the
And then within the
The "use client" directive (see docs) makes this a client component so that it has access to local state. I haven't done any extensive testing here, but I believe the tradeoff is that next-mdx-remote will be included in the JS bundle sent to the client and that the work of translating will take place there, even if the app is otherwise statically rendered. |
I can't even get it to work using the workarounds pasted above. When I try, I get Does anybody already have a repo they're willing to share that works (Next 13 + app directory + MDX), even if its using a workaround? |
I still got the |
This worked for me (new appDir with SSG), thanks @mikewheaton ! |
undefined useState too. |
I am not able to use MDXContent in a clientcomp. I am getting impl code: // Article.tsx
'use client';
import { MDXRemote, MDXRemoteProps } from 'next-mdx-remote';
export function Article({ content }: { content: MDXRemoteProps }) {
return <MDXRemote {...content} />;
} // page.tsx
import { serialize } from 'next-mdx-remote/serialize';
import { Article } from '../../../components/Article';
import { getPostBySlug } from '../../../utils/markdownHelper';
type PageProps = {
params: { post: string };
searchParams?: { [key: string]: string | string[] | undefined };
};
export default async function Page({ params }: PageProps) {
const { content } = getPostBySlug(params.post);
const mdx = await serialize(content);
return (
<div>
<Article content={mdx} />
</div>
);
} using node 18 w/ next@13.0.6 and next-mdx-remote@^4.2.0 |
It works if you force-downgrade "resolutions": {
"@mdx-js/mdx": "2.1.5",
"@mdx-js/react": "2.1.5"
}, |
Can confirm this works. For the npm users, the key here is "overrides" "overrides": {
"@mdx-js/mdx": "2.1.5",
"@mdx-js/react": "2.1.5"
} |
I can confirm that it works. But I have one question for you @mmiszy. Doing this will break anything in future if you are using Next.js v13? The point is what are the stakes if we use version |
@j471n sadly, I have no clue. Let's see if the maintainers reply. |
thanks, @mmiszy for your temp solution, as maybe someone does not know about worth reading |
There is a better temporary solution without the need to downgrade const mdxSource = await serialize(content, {
mdxOptions: {
remarkPlugins: [],
rehypePlugins: [],
+ development: false,
},
}); In mdx-js/mdx#2045, compiled MDX source will use |
I opened a PR (#323) to fix this issue. Before it gets merged, you can use the temporary workaround. |
Until `next-mdx-remote` supports Next 13, we need to workaround the `_jsxDEV` error. For more info, @see hashicorp/next-mdx-remote#307 (comment)
I downgraded to
and that fixed the issue. |
It looks there is an entanglement with next-remote-watch - at least in my settings. In "scripts": {
"dev": "next-remote-watch ../content/pages ./public/static/locales",
} Running |
Thanks y'all, I'll take a look at some of the reported issues with 4.2.1. Note that the previous workaround should likely be removed, and you might need to do a full re-install of
(or whatever the equivalent would be for your package manager of choice) |
Hm, after combining all workarounds it worked. I got: updated to version 4.2.1
( So to remove the previous workaround was not successful. |
This is a working configuration. Just did
|
Using SSR, then it's not needed as it turned out. But if you use serialize on client side, then the mdxOptions is needed and have to be switched depending on dev and prod mode.
|
See hashicorp/next-mdx-remote#307 (comment) Signed-off-by: Richard Wall <richard.wall@jetstack.io>
Hey y'all, we've now get experimental support for server components, and the |
Hi, thanks for this release!
with compileMdx:
Should I create new issue or is it some error on my side? |
I am getting the same exact issues @pszafer, not an error on your side |
I ran into the same issue and solved it using It's documented on the Next 13 beta docs. |
I'm getting a different error when trying to use
Probably on my end but I can't seem to figure out what might be causing it. AllI changed was upgrading Adding the |
A slight update to the above ☝️ I was using a custom component to wrap import { MDXRemote } from 'next-mdx-remote/rsc'
import MDXComponents from '@components/mdx-components'
import type { VFileCompatible } from 'vfile'
import type { SerializeOptions } from 'next-mdx-remote/dist/types'
export function MdxContent({ source, options }: { source: VFileCompatible; options?: SerializeOptions }) {
// @ts-expect-error Server Component
return <MDXRemote {...source} components={MDXComponents} {...options} />
} When I replaced that component in all of my pages with the native |
I followed the documentation along with adding the above suggestion of
My code is: // components/MDXComp
import { MDXRemote } from 'next-mdx-remote/rsc'
import { paragraph } from "./MarkDownComponents"
const components = {
p: paragraph
}
export function MDXContent(props:any) {
return (
// @ts-expect-error Server Component
<MDXRemote {...props} components={{ ...components, ...(props.components || {}) }}
/>
)
} // components/MarkDownComponents
import { Text ... } from "@chakra-ui/react"
...
const paragraph = (props: any) => (
<Text fontSize="1.1rem" lineHeight="1.4rem">{props.children}</Text>
)
...
export { paragraph ... } // app/page.tsx
...
import { MDXContent } from "../../../components/MDXComp";
...
export default function PAGE(props: any) {
...
return (
<>
...
<MDXContent source={MARKDOWNSOURCE} />
...
</>
)
} UpdateAfter some further digging I have discovered that this issue maybe caused from needing to use the |
Same for me.
@ramblehead Did you find a current workaround? |
@yannickschuchmann not really - just found a versions combination that seems to work for me: |
Just because I have read it over this whole issue. For safe & clear communication it's often better to give exact versions, especially for combinations of packages because
As an example: for both variations your package manager will install the exact same packages. Hope it's not too dramatic, I just love some helpful clarity in version talking :) @ramblehead ofc not meant personally, maybe you even meant "4.2.1 and upwards". :) |
@yannickschuchmann you are correct - I meant precise versions not P. S. When having a choice I tend to use yarn 3 monorepos to enforce versions consistency, |
Hi y'all, As discussed above, we should fully support next 13 as well as the |
I've noticed that next-mdx-remote doesn't work with Next.js 13.
To reproduce the issue, I tried running the official example with-mdx-remote using Next.js 13 and it doesn't work. Trying to load the example post, I get the following error:
How to reproduce
yarn dev
In my own project, I'm getting a similar error relating to imports of components, so I assume the issue might be related to changes in Next.js' bundler or build system.
I don't get the error if I run the tests in this repo (hashicorp/next-mdx-remote) with Next.js 13. For me that's another hint that the error might be related to bundling, since in this repo the test doesn't import
next-mdx-remote
throughnode_modules
(seenext-mdx-remote/__tests__/fixtures/basic/pages/index.jsx
Lines 5 to 6 in f5b0e74
Compiled Output
Here is the compiled output of
node_modules/next-mdx-remote/index.js
:The text was updated successfully, but these errors were encountered: