Skip to content

Mermaid rendering to PDF broken with quarto install chromium version #10961

Closed

Description

@sasja-san

Bug description

I'm not able to render this code to a PDF. The Mermaid code was taken from here: https://quarto.org/docs/authoring/diagrams.html#mermaid

---
title: Mermaid Test
format: pdf
---


# Hello!


```{mermaid}
sequenceDiagram
  participant Alice
  participant Bob
  Alice->>John: Hello John, how are you?
  loop Healthcheck
    John->>John: Fight against hypochondria
  end
  Note right of John: Rational thoughts <br/>prevail!
  John-->>Alice: Great!
  John->>Bob: How about you?
  Bob-->>John: Jolly good!
```

Here's the error I get:

$ quarto render mermaid-test.qmd
ERROR: Internal Error: Couldn't find an svg element in svg string

This is a bug in quarto. We apologize for the inconvenience.
Please consider reporting it at https://github.com/quarto-dev/quarto-cli. Thank you!

Stack trace:
    at resolveSize (file:///home/sasja/.quarto/quarto-cli/src/core/svg.ts:24:11)
    at eventLoopTick (ext:core/01_core.js:175:7)
    at async makePng (file:///home/sasja/.quarto/quarto-cli/src/core/handlers/mermaid.ts:353:11)
    at async makeDefault (file:///home/sasja/.quarto/quarto-cli/src/core/handlers/mermaid.ts:435:16)
    at async Object.cell (file:///home/sasja/.quarto/quarto-cli/src/core/handlers/mermaid.ts:475:14)
    at async Promise.all (index 0)
    at async Object.document (file:///home/sasja/.quarto/quarto-cli/src/core/handlers/base.ts:577:20)
    at async handleLanguageCells (file:///home/sasja/.quarto/quarto-cli/src/core/handlers/base.ts:529:34)
    at async file:///home/sasja/.quarto/quarto-cli/src/command/render/render-files.ts:631:41
    at async withTimingAsync (file:///home/sasja/.quarto/quarto-cli/src/core/timing.ts:50:20)

Quarto check & version

I'm using the latest commit on main branch:

git show -s --format="%as %H"
2024-10-02 9d00acae2607c1d0fae479b0b8f830145454b207

From quarto check:

Quarto 99.9.9
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.4.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.46.3: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 99.9.9
      commit: 9d00acae2607c1d0fae479b0b8f830145454b207
      Path: /home/sasja/.quarto/quarto-cli/package/dist/bin

[✓] Checking tools....................OK
      TinyTeX: v2024.03.13
      Chromium: 869685

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /home/sasja/.TinyTeX/bin/x86_64-linux
      Version: 2024

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.12.5
      Path: /usr/bin/python3
      Jupyter: 5.7.2
      Kernels: python3

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........(None)

      Unable to locate an installed version of R.
      Install R from https://cloud.r-project.org/

Activity

  1. added
    bug
    on Oct 3, 2024
  2. cderv commented on Oct 3, 2024

    @cderv
    Member

    Just to share on Windows this is rendering ok for me.

  3. added
    needs-repro
    on Oct 3, 2024
  4. cscheid commented on Oct 3, 2024

    @cscheid
    Member

    I also can't repro myself, either on 1.6.18 or main, on macOS.

  5. sasja-san commented on Oct 8, 2024

    @sasja-san
    Author

    I'm using Manjaro Linux. Is there something I could do to test what might be going on? Maybe there are clues in the call stack?

  6. mcanouil commented on Oct 8, 2024

    @mcanouil
    Collaborator
  7. sasja-san commented on Oct 8, 2024

    @sasja-san
    Author

    @sasja-san See https://quarto.org/docs/troubleshooting/index.html

    The only thing that I did there (which was applicable to me, the env variable settings gave me nothing) was update my install of TinyTex from v2024.03.13 to v2024.10 - but the error remains.

    I dug around a bit in the code trying to figure out what's wrong. I don't know any typescript so I don't really know what I'm doing. Anyway, in src/core/svg.ts i added some code at around line 23:

     const dom = (await getDomParser()).parseFromString(svg, "text/html");
      const svgEl = dom?.querySelector("svg");
    
      if (!svgEl) {
        throw new InternalError("Couldn't find an svg element in svg string"
                                + "\n\tdom   = " + dom
                                + "\n\tsvgEl = " + svgEl);
      }

    which gave me this output:

    ERROR: Internal Error: Couldn't find an svg element in svg string
    	dom   = [object EventTarget]
    	svgEl = null
    

    I would try to make a long string with all the things in this dom object as well, but I don't really know how that's done. Basically what I want to do is something like

    let s = "";
    foreach e in dom {
        s += e;
    }
    

    If anyone could help me with this, then I can dig a little deeper.

  8. github-actions commented on Oct 23, 2024

    @github-actions
    Contributor

    Thank you for using Quarto and reporting an issue!

    Unfortunately, this issue is now considered stale because it has been opened since 14 days without providing a "working" reproducible example to help us investigate.
    If you are still facing the issue, please review the "Bug Reports" guide on how to provide a fully reproducible example as a self-contained Quarto document or a link to a Git repository.
    Without a reproducible example, it is unlikely that the issue will be addressed.

    You can share a Quarto document using the following syntax, i.e., using more backticks than you have in your document (usually four ````).

    ````qmd
    ---
    title: "Reproducible Quarto Document"
    format: html
    ---
    
    This is a reproducible Quarto document using `format: html`.
    It is written in Markdown and contains embedded R code.
    When you run the code, it will produce a plot.
    
    ```{r}
    plot(cars)
    ```
    
    The end.
    ````
    
  9. added
    stale
    on Oct 23, 2024
  10. cderv commented on Oct 23, 2024

    @cderv
    Member

    @sasja-san can you try with Quarto v1.5 and latest Quarto v1.6 ? Though we are facing #11135 if you have recent build of chrome :(

  11. cscheid commented on Oct 23, 2024

    @cscheid
    Member

    Yeah, I think this is "just" a duplicate of #11135

  12. sasja-san commented on Oct 28, 2024

    @sasja-san
    Author

    Sorry I missed this. The tab was active on a virtual desktop I didn't look at for a while, so I cleared the notification without noticing.

    I installed and tested with both 1.5.57 and 1.6.31.

    Verson 1.6 gave me the same error but version 1.5 gave me a pdf.

    Image

    As I said previously, I don't know any typescript. But if any of you have suggestions for some code I could use to proceed with poking around I'd gladly try it out.

  13. cderv commented on Oct 29, 2024

    @cderv
    Member

    Is this still with the same example shared above in #10961 (comment) ?

    I still can't reproduce. What is your chrome version on your system ?

    To debug further, you can activate Debug logging (https://quarto.org/docs/troubleshooting/#verbose-mode) and see if anything else is helping.

    The thing I would if I was able to reproduce would be to try interactively debug dev version inside VSCODE. We don't have a step by step guide for that yet, so one would need to be confortable with VSCODE debugging and quarto dev.

    Hopefully, we'll manage to find a reproducible environment for that. Which OS are you on ?

  14. removed
    stale
    on Oct 29, 2024
  15. sasja-san commented on Oct 29, 2024

    @sasja-san
    Author

    Is this still with the same example shared above in #10961 (comment) ?

    Yes.

    What is your chrome version on your system ?

    From quarto check.

    [✓] Checking tools....................OK
          TinyTeX: v2024.10
          Chromium: 869685
    

    To the best of my knowledge I have no other instances of chromium installed. Except maybe bundled ones, if that's what Electron is doing.
    Do you have some command for me which I could run to check that I don't have some fishy stuff on my system?

    so one would need to be confortable with VSCODE debugging and quarto dev.

    I'm cool with this. I even wrote a tutorial (rendered using Quarto) about debugging in VS Code:
    https://github.com/sasja-san/vscode-remote-debug-example

    I have pretty much zero experience of TypeScript, though. But that's subject to change ;)

    Which OS are you on ?

    Image

    (though the image there lies, as I have now installed a 65W CPU in my nine years old powerhouse of a computer XD)

  16. 41 remaining items

  17. mcanouil commented on Oct 15, 2025

    @mcanouil
    Collaborator

    FYI for the latest Brave 1.83.112, the chromium version used is 141.0.7390.70 (https://brave.com/latest/)
    So the version of chromium/brave reported is very odd.

  18. frucht-salat commented on Oct 17, 2025

    @frucht-salat

    Hi, sorry to be late. I tried with chromium and brave, that might have been confusing.

    I got this running btw on my Linux with docker:

    ARG IMAGE=python:3.13-slim
    
    FROM $IMAGE
    
    RUN apt-get update && apt-get install -y \
        curl \
        wget \
        unzip \
        bash \
        build-essential \
        libffi-dev \
        libssl-dev \
        pkg-config \
        cmake \
        gcc \
        python3-dev \
        libfreetype6-dev \
        libpng-dev \
        nodejs \
        npm \
        chromium \
        groff \
        less \
        && rm -rf /var/lib/apt/lists/* \
        && rm -rf /tmp/*
    
    RUN npm install -g @mermaid-js/mermaid-cli
    
    # Create a wrapper script for chromium with Docker-safe flags
    RUN echo '#!/bin/bash\nexec /usr/bin/chromium --no-sandbox --disable-setuid-sandbox --disable-dev-shm-usage --disable-gpu "$@"' > /usr/local/bin/chromium-wrapper && \
        chmod +x /usr/local/bin/chromium-wrapper
    
    RUN QUARTO_VERSION=1.8.25 && \
        curl -LO -k "https://github.com/quarto-dev/quarto-cli/releases/download/v${QUARTO_VERSION}/quarto-${QUARTO_VERSION}-linux-amd64.tar.gz" && \
        tar -C /opt -xvzf "quarto-${QUARTO_VERSION}-linux-amd64.tar.gz" && \
        ln -s "/opt/quarto-${QUARTO_VERSION}/bin/quarto" /usr/local/bin/quarto && \
        rm -rf "quarto-${QUARTO_VERSION}-linux-amd64.tar.gz"
    
    RUN mkdir /jobs/ && \
        useradd -m -d /jobs/ -s /bin/bash quser && \
        chown -R quser:quser /jobs/
    
    COPY --chown=quser:quser requirements.txt /tmp/requirements.txt
    USER quser
    
    ENV QUARTO_CHROMIUM=/usr/local/bin/chromium-wrapper
    RUN quarto install tinytex
    RUN pip install -r /tmp/requirements.txt && \
        rm -rf /tmp/requirements.txt
    

    Not sure if the chromium flags are needed, but this renders a PDF. Only problem is, that the mermaid diagrams are cut if too big.

    Image
  19. cderv commented on Oct 17, 2025

    @cderv
    Member

    Only problem is, that the mermaid diagrams are cut if too big

    This is a different issue, and possibly related to setting fig size for diagram.

    Otherwise, glad it works with you docker setup

  20. Xenon-Chameleon commented on Oct 23, 2025

    @Xenon-Chameleon

    On MacOS ARM via Positron and Quarto 1.8.25 I'm having the same issues with the same error rendering PDF files that @sasja-san originally posted with the same stack trace. I tried tinytex and lualatex engines.

    The live preview and html render works but I couldn't render my Mermaid chart with the chromium installed via quarto install chromium.

    The only workaround I could find was installing the Google Chrome application. Quarto was able to recognize and use that to render the pdf. The Brave browser I had installed was not recognized the same way.

    Is this still a problem with headless chromium or is there a different method I should use to install Chromium? I would prefer headless Chromium or a different method of rendering Mermaid than keeping the Chrome browser on my computer.

  21. cderv commented on Oct 23, 2025

    @cderv
    Member

    Is this still a problem with headless chromium or is there a different method I should use to install Chromium?

    It is a problem with the version installed by quarto install chromium. You need another chrome or chromium installed without quarto. I'll fix that for 1.9.

    I would prefer headless Chromium

    As you'll find on some thread, using chrome-headless-shell binary will work, but you need to set the env var QUARTO_CHROMIUM for Quarto to use this chrome version.

    You should also be able to use a recent chromium binary.

  22. sakthivelvelumani commented on Oct 24, 2025

    @sakthivelvelumani

    I have the same problem but thanks to @Zujiry I was able to render my document with mermaid on docker.

  23. davidnortes commented on Jan 22, 2026

    @davidnortes

    I encountered the same problem today. Just in case it provides new information or new hints for a solution: the only way I have found to solve it is to stop using the Snap version of Chromium altogether. As soon as I switched to the .deb version of Chrome, document rendering worked fine.

    operating system: ubuntu 24.04
    quarto version: 1.8.27
    chromium: 143.0.7499.192 Snap
    chrome: 144.0.7559.96 (deb)

  24. cderv commented on Feb 13, 2026

    @cderv
    Member

    Next pre-release 1.9.21 will have a quarto install chrome-headless-shell that will install a lighter-weight binary that chromium and will solve the mermaid issue.

  25. benz0li commented on Mar 23, 2026

    @benz0li
    Contributor

    I tested with Quarto 1.9.36 + Pandoc 3.8.3 + Chrome Headless Shell again.


    The following hangs:

    On a Linux machine with Docker installed:

    docker run --rm -ti glcr.b-data.ch/r/verse:4.5.3 bash
    quarto install chrome-headless-shell
    nano mermaid.qmd
    ---
    title: Test rendering mermaid to docx
    format: docx
    ---
    
    
    ```{mermaid}
    gantt
        section TODO
            Test rendering mermaid: 2025-03-12, 30d
    ```
    quarto render mermaid.qmd

    The following works:

    On a Linux machine with Docker installed:

    docker run --rm -ti glcr.b-data.ch/r/verse:4.5.3 bash
    cd $HOME
    quarto install chrome-headless-shell
    nano mermaid.qmd
    ---
    title: Test rendering mermaid to docx
    format: docx
    ---
    
    
    ```{mermaid}
    gantt
        section TODO
            Test rendering mermaid: 2025-03-12, 30d
    ```
    quarto render mermaid.qmd
    pandoc 
      to: docx
      output-file: mermaid.docx
      default-image-extension: png
      variables: {}
      
    metadata
      engines:
        - path: /opt/quarto/share/extension-subtrees/julia-engine/_extensions/julia-engine/julia-engine.js
      title: Test rendering mermaid to docx
      
    Output created: mermaid.docx
    
    

    ℹ️ The only difference: cd $HOME

  26. mcanouil commented on Mar 23, 2026

    @mcanouil
    Collaborator

    @benz0li Could you open a new issue referencing this one? This is a closed issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugchromiumdiagrams-mermaid

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions