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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read properties of undefined (reading 'children') #91

Closed
johackim opened this issue May 26, 2023 · 1 comment
Closed

Comments

@johackim
Copy link
Contributor

johackim commented May 26, 2023

Hello @sjwall 😉

Describe the bug

Since yesterday, I have this error:

file:///home/johackim/Dev/test/node_modules/mdx-mermaid/lib/mdxast-mermaid.mjs:94
    return tree.children[0].children;
                            ^

TypeError: Cannot read properties of undefined (reading 'children')
    at outputSVG (file:///home/johackim/Dev/test/node_modules/mdx-mermaid/lib/mdxast-mermaid.mjs:94:29)
    at async transformer (file:///home/johackim/Dev/test/node_modules/mdx-mermaid/lib/mdxast-mermaid.mjs:122:32)

Node.js v18.16.0

To Reproduce

Steps to reproduce the behaviour including how the markdown file is processed:

// test.mjs

import * as runtime from 'react/jsx-runtime';
import { runSync, compile } from '@mdx-js/mdx';
import { renderToStaticMarkup } from 'react-dom/server';

const markdown = `
## Hello world

\`\`\`mermaid
graph LR;
    Acquisition-->Activation-->Rétention-->Recommandation-->Revenu
\`\`\`
`;

const code = String(await compile(markdown, {
    outputFormat: 'function-body',
    remarkPlugins: [
        [(await import('mdx-mermaid')).default, { output: 'svg' }],
    ],
}));

const { default: Content } = runSync(code, runtime);
const html = renderToStaticMarkup(Content());

console.log(html);

Additional context

Here my package.json :

{
  "devDependencies": {
    "@mdx-js/mdx": "2.1.0",
    "mdx-mermaid": "^2.0.0-rc7",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  }
}
@johackim
Copy link
Contributor Author

I confirm the fix #90 from @paul-sachs solves the bug.

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