mermaid-js / mermaid-cli

Command line tool for the Mermaid library
MIT License
2.31k stars 223 forks source link

Exception creating an Image using ELK and subgraph. #594

Open hqv1 opened 11 months ago

hqv1 commented 11 months ago

Describe the bug I'm attempting to create an SVG from a Markdown file containing a mermaid diagram. I'm using ELK as the default renderer. The CLI crashes at the Mermaid subgraph. It is able to create an SVG file if I remove the subgraph.

To Reproduce Steps to reproduce the behavior:

  1. Create a Markdown file with a mermaid diagram with ELK as the default renderer and with a subgraph. This is mine.
%%{init: {"flowchart": {"defaultRenderer": "elk"}}}%%
flowchart TB

subgraph hi
        a
end

Or without the mermaid code block

%%{init: {"flowchart": {"defaultRenderer": "elk"}}}%%
flowchart TB

subgraph hi
       a
end

Run the CLI mmdc -i input_diagram.md -o output.svg

This is the error I get

Error: Evaluation failed: TypeError: Cannot read properties of undefined (reading 'children')
    at file:///Users/xxxx/.nvm/versions/node/v18.7.0/lib/node_modules/@mermaid-js/mermaid-cli/dist/index.html:1358:3410
    at Array.forEach (<anonymous>)
    at M3e (file:///Users/xxxx/.nvm/versions/node/v18.7.0/lib/node_modules/@mermaid-js/mermaid-cli/dist/index.html:1358:3396)
    at file:///Users/xxxx/.nvm/versions/node/v18.7.0/lib/node_modules/@mermaid-js/mermaid-cli/dist/index.html:1358:3507
    at Array.forEach (<anonymous>)
    at M3e (file:///Users/xxxx/.nvm/versions/node/v18.7.0/lib/node_modules/@mermaid-js/mermaid-cli/dist/index.html:1358:3396)
    at Object.fjt [as draw] (file:///Users/xxxx/.nvm/versions/node/v18.7.0/lib/node_modules/@mermaid-js/mermaid-cli/dist/index.html:1358:5185)
    at async Object.jDt [as render] (file:///Users/xxxx/.nvm/versions/node/v18.7.0/lib/node_modules/@mermaid-js/mermaid-cli/dist/index.html:88:840)
    at ExecutionContext._ExecutionContext_evaluate (file:///Users/xxxx/.nvm/versions/node/v18.7.0/lib/node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer-core/lib/esm/puppeteer/common/ExecutionContext.js:254:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ExecutionContext.evaluate (file:///Users/xxxx/.nvm/versions/node/v18.7.0/lib/node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer-core/lib/esm/puppeteer/common/ExecutionContext.js:143:16)
    at async CDPJSHandle.evaluate (file:///Users/xxxx/.nvm/versions/node/v18.7.0/lib/node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer-core/lib/esm/puppeteer/common/JSHandle.js:56:16)
    at async CDPElementHandle.$eval (file:///Users/xxxx/.nvm/versions/node/v18.7.0/lib/node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer-core/lib/esm/puppeteer/common/ElementHandle.js:86:24)
    at async renderMermaid (file:///Users/xxxx/.nvm/versions/node/v18.7.0/lib/node_modules/@mermaid-js/mermaid-cli/src/index.js:246:22)
    at async file:///Users/xxx/.nvm/versions/node/v18.7.0/lib/node_modules/@mermaid-js/mermaid-cli/src/index.js:442:41
    at async Promise.all (index 0)
    at async run (file:///Users/xxxx/.nvm/versions/node/v18.7.0/lib/node_modules/@mermaid-js/mermaid-cli/src/index.js:461:22)
    at async cli (file:///Users/xxxx/.nvm/versions/node/v18.7.0/lib/node_modules/@mermaid-js/mermaid-cli/src/index.js:184:3)

Expected behavior I expect an SVG to be generated.

Desktop (please complete the following information):

bmitc commented 11 months ago

I am seeing this issue as well. This is a critical issue since I am using Mermaid for automatically generated graphs that are large and complex, for which the elk renderer is essential as the default renderer can't handle the graphs well. I see the exception for any output format.

Also, the Mermaid Live Editor can't handle these type of graphs either.

image

In fact, the only way I have been able to even render these diagrams is with GitHub's Mermaid rendering in Markdown documents.

phil-flip commented 4 months ago

Issue is still present, but a different error

phil-flip commented 4 months ago

After checking again, this issue doesn't seem to be present anymore. But there seems to be an issue with empty subgraphs. https://github.com/mermaid-js/mermaid/issues/5402