kentcdodds / mdx-bundler

🦤 Give me MDX/TSX strings and I'll give you back a component you can render. Supports imports!
MIT License
1.78k stars 75 forks source link

[error]Cannot process MDX file with esbuild #223

Open jialouluos opened 11 months ago

jialouluos commented 11 months ago

v10.0.1 bug?

import remarkGFM from 'remark-gfm';
const { code} = await bundleMDX({
        source: source.replaceAll(/\$.*(?<val>[\>\=\<]+).*\$/gm, `{'$<val>'}`),
        mdxOptions(options) {
            options.remarkPlugins = [
                ...(options.remarkPlugins ?? []),
                remarkGFM,
            ];
            options.rehypePlugins = [...(options.rehypePlugins ?? [])];
            return options;
        },
    });

show:Cannot process MDX file with esbuild [plugin @mdx-js/esbuild]

version @9 is running properly

bjarkebech commented 11 months ago

I had this same error today.

I'm using Remix and had mdx-bundler inside serverDependenciesToBundle in remix.config.js, which was required for v9.x.

Removing it again fixed the issue.

I.e.:

//remix.config.js
serverDependenciesToBundle: [
  /^mdx-bundler.*/", // remove this entry
],
jialouluos commented 11 months ago

I had this same error today.

I'm using Remix and had mdx-bundler inside serverDependenciesToBundle in remix.config.js, which was required for v9.x.

Removing it again fixed the issue.

I.e.:

//remix.config.js
serverDependenciesToBundle: [
  /^mdx-bundler.*/", // remove this entry
],

I removed remark-gfm and it worked, but I need remark-gfm

jialouluos commented 11 months ago

Does the gfm plugin for mdx-bundler(v10) exist in error handling for backquotes? The gfm plugin for mdx-bundler(v9) handles backquotes correctly

bjarkebech commented 11 months ago

We're using remark-gfm in production as well with no issues - are you using mdx-bundler@10.0.1 and remark-gfm@4.0.0?

Here's our full serverDependenciesToBundle - maybe it will work for you 🤞🏻


serverDependenciesToBundle: [
    // MDX:
    /^rehype.*/,
    /^remark.*/,
    /^unified.*/,
    /^unist.*/,
    /^mdast.*/,
    /^micromark.*/,
    "devlop",
    "ccount",
    "markdown-table",
    "zwitch",
    "fault",
    "decode-named-character-reference",
    "longest-streak",
    "character-entities",
  ],
airtonix commented 8 months ago

getting this error when trying to using:


import {bundleMDX} from 'mdx-bundler'
import { readSync } from 'to-vfile'

import remarkShikiTwoslash from 'remark-shiki-twoslash'

const mdxSource = readSync(`src/components/thing.md`)

const result = await bundleMDX({
  source: mdxSource.toString(),
  mdxOptions (options) {
    options.remarkPlugins = [
       [remarkShikiTwoslash, { theme: "dark-plus" }]
    ]
    return options
  }

})

const {code, frontmatter} = result

export { code, frontmatter }

https://github.com/airtonix/shaku-astro-mdxbundler-bug-223

hxlhxl commented 2 weeks ago

I came to this problem when I write the ill mermaid graph code like this

```mermaid
a -> b

after a deep look at the mdx-mermaid plugin process logic

![image](https://github.com/user-attachments/assets/3b786707-38ab-4bd3-b3cf-16fd9edd6005)

I got no error but the undefined empty result of this function.
It occured to me that maybe something wrong with my mermaid code.
After I chagned to the correct code.
graph TD;
    A-->B;


Error disappeard