Skip to content

feat!: make @mermaid-js/mermaid-cli an optional peer dependency - #298

Merged
keonik merged 1 commit into
mainfrom
feat/293-optional-mermaid-cli
Aug 25, 2026
Merged

feat!: make @mermaid-js/mermaid-cli an optional peer dependency#298
keonik merged 1 commit into
mainfrom
feat/293-optional-mermaid-cli

Conversation

@keonik

@keonik keonik commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Closes #293
Closes #176

⚠️ Breaking — this is the 3.0 change. Ships as a major changeset.

What

mmdc is only ever invoked as an external binary (node_modules/.bin/mmdc), never imported. And for .md output generate returns long before anything touches it. So every user was installing the CLI — plus mermaid (~76 MB) and a headless Chromium via its puppeteer peer — whether or not they could ever use it.

It moves to an optional peer:

"peerDependencies": {
  "@prisma/client": "^5.0.0 || ^6.0.0 || ^7.0.0",
  "@mermaid-js/mermaid-cli": "^11.0.0"
},
"peerDependenciesMeta": {
  "@mermaid-js/mermaid-cli": { "optional": true }
}

Thanks @RPDeshaies and @mo-ayala for the original Docker-image write-up on #176 — this is the fix for that.

Migration

Rendering .svg / .png / .pdf — the default output is ./prisma/ERD.svg, so this is most people:

npm i -D @mermaid-js/mermaid-cli puppeteer

Rendering .md / .mmd: nothing to do, and you can now drop both packages.

The README install block, the output-extension table, and a "Upgrading to 3.x" section all say this.

Also in here

Small things that only make sense alongside the above:

  • .mmd output — writes bare mermaid with no code fence. Remove puppeteer dependency when outputting mermaid markdown #176 asked for .md/.mmd; only .md existed.

  • An actionable error. Previously a missing CLI gave Expected mermaid CLI at <path> or undefined but this package was not found. Now:

    prisma-erd-generator: could not find the mermaid CLI (mmdc).
    
    Rendering to .svg, .png or .pdf needs @mermaid-js/mermaid-cli, which is an
    optional peer dependency so that it is not installed for everyone:
    
        npm i -D @mermaid-js/mermaid-cli puppeteer
    
    Already installed? Point the generator at the binary instead:
    
        generator erd {
          provider = "prisma-erd-generator"
          mmdcPath = "node_modules/.bin"
        }
    
    Don't need an image? Markdown output renders with no browser at all:
    
        output = "../ERD.md"
    
    Searched <path> and `find ../.. -name mmdc`.
    
  • CLI resolved before the puppeteer config is built. That config exists only to be passed to mmdc, so building it first meant a missing CLI got buried under the arm64 which chromium probe dumping a Command failed: which chromium stack trace first. Verified before/after in an isolated directory.

  • find ../.. -name mmdc no longer crashes. It was an unguarded execSync, so on Windows (no find) or a missing parent it threw a spawn error instead of falling through to "not found" — plausibly part of Installation bug: reify:poppeteer-core: timing... #183. Now a failed search is just a miss.

Testing

  • New __tests__/textOutput.test.ts.md fencing, .mmd bare output, and a guard that @mermaid-js/mermaid-cli stays out of dependencies and stays marked optional, so this doesn't silently regress.
  • Full suite (30 files / 35 tests) passes against Prisma 7. @mermaid-js/mermaid-cli moved to devDependencies, so CI and local runs still render real SVGs.
  • Manually reproduced the missing-CLI path in an isolated directory with no node_modules to confirm the message and the ordering fix.

@keonik
keonik force-pushed the feat/293-optional-mermaid-cli branch from c489076 to ade7141 Compare August 19, 2026 19:22
mmdc is only ever invoked as an external binary, and text output returns
before it is ever reached, so every user was installing the CLI, mermaid and
a headless Chromium whether or not they could use them.

Alongside that:
- add .mmd output (bare mermaid, no code fence)
- fail with an actionable message naming the package to install
- resolve the CLI before building the puppeteer config, so a missing CLI is
  not buried under the arm64 `which chromium` probe
- stop `find ../.. -name mmdc` from crashing where find is unavailable

BREAKING CHANGE: users rendering .svg/.png/.pdf must install
@mermaid-js/mermaid-cli themselves.

Closes #293
Closes #176
@keonik
keonik force-pushed the feat/293-optional-mermaid-cli branch from ade7141 to c4d95e6 Compare August 20, 2026 02:20
@keonik
keonik merged commit 005fad3 into main Aug 25, 2026
18 checks passed
@keonik
keonik deleted the feat/293-optional-mermaid-cli branch August 25, 2026 04:10
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

Successfully merging this pull request may close these issues.

mermaid-cli is a hard dependency even for Markdown output, where it is never executed Remove puppeteer dependency when outputting mermaid markdown

1 participant