mermaid-js / mermaid-cli

Command line tool for the Mermaid library
MIT License
2.23k stars 210 forks source link

How can I configure maxEdges using the CLI? (Error: Too many edges) #636

Open mlandisbqs opened 6 months ago

mlandisbqs commented 6 months ago

I'm trying to use mermaid to visualize NestJS Dependencies. We have a ton of modules/dependencies and the generated source for the diagram has between 700 and 800 edges.

Max edges should be configurable based on this PR: https://github.com/mermaid-js/mermaid/pull/5086/files

How do I configure it? I've tried creating a config file and passing it...

$ cat .stats.mermaid.json 
{
  "maxEdges": 1000000
}

Sample run...

npx @mermaid-js/mermaid-cli -c .stats.mermaid.json -i .stats.mermaid.md -o .stats.diagram.svg
Found 1 mermaid charts in Markdown input

Error: Evaluation failed: Error: Too many edges
    at dbt (file:///Users/mlandis/.npm/_npx/668c188756b835f3/node_modules/@mermaid-js/mermaid-cli/dist/index.html:103:13448)
    at Object.Fbt [as addLink] (file:///Users/mlandis/.npm/_npx/668c188756b835f3/node_modules/@mermaid-js/mermaid-cli/dist/index.html:103:13584)
    at Object.performAction (file:///Users/mlandis/.npm/_npx/668c188756b835f3/node_modules/@mermaid-js/mermaid-cli/dist/index.html:98:6972)
    at Lh.parse (file:///Users/mlandis/.npm/_npx/668c188756b835f3/node_modules/@mermaid-js/mermaid-cli/dist/index.html:100:892)
    at PUt.parse (file:///Users/mlandis/.npm/_npx/668c188756b835f3/node_modules/@mermaid-js/mermaid-cli/dist/index.html:64:512)
    at new PUt (file:///Users/mlandis/.npm/_npx/668c188756b835f3/node_modules/@mermaid-js/mermaid-cli/dist/index.html:64:247)
    at GjA (file:///Users/mlandis/.npm/_npx/668c188756b835f3/node_modules/@mermaid-js/mermaid-cli/dist/index.html:64:824)
    at async Object.N2e [as render] (file:///Users/mlandis/.npm/_npx/668c188756b835f3/node_modules/@mermaid-js/mermaid-cli/dist/index.html:87:1146)
    at ExecutionContext._ExecutionContext_evaluate (file:///Users/mlandis/.npm/_npx/668c188756b835f3/node_modules/puppeteer-core/lib/esm/puppeteer/common/ExecutionContext.js:254:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async ExecutionContext.evaluate (file:///Users/mlandis/.npm/_npx/668c188756b835f3/node_modules/puppeteer-core/lib/esm/puppeteer/common/ExecutionContext.js:143:16)
    at async CDPJSHandle.evaluate (file:///Users/mlandis/.npm/_npx/668c188756b835f3/node_modules/puppeteer-core/lib/esm/puppeteer/common/JSHandle.js:56:16)
    at async CDPElementHandle.$eval (file:///Users/mlandis/.npm/_npx/668c188756b835f3/node_modules/puppeteer-core/lib/esm/puppeteer/common/ElementHandle.js:86:24)
    at async renderMermaid (file:///Users/mlandis/.npm/_npx/668c188756b835f3/node_modules/@mermaid-js/mermaid-cli/src/index.js:246:22)
    at async file:///Users/mlandis/.npm/_npx/668c188756b835f3/node_modules/@mermaid-js/mermaid-cli/src/index.js:442:41
    at async Promise.all (index 0)
    at async run (file:///Users/mlandis/.npm/_npx/668c188756b835f3/node_modules/@mermaid-js/mermaid-cli/src/index.js:461:22)
    at async cli (file:///Users/mlandis/.npm/_npx/668c188756b835f3/node_modules/@mermaid-js/mermaid-cli/src/index.js:184:3)
aloisklink commented 4 months ago

I think I know what the issue is. The "Error: Too many edges" error is from mermaid v10.6.1 or earlier. You need at least version v10.7.0 or later to support the maxEdges feature.

Afterwards, you'll either get a Edge limit exceeded. ${edges.length} edges found, but the limit is ${config.maxEdges}. error, or it will work!

npx by default uses a cached version of @mermaid-js/mermaid-cli, so you have to run npx @mermaid-js/mermaid-cli@latest to download and install the latest version.