Skip to content

Fix mermaid console errors - #124

Open
paulbrimicombe wants to merge 1 commit into
bbc:mainfrom
paulbrimicombe:fix-mermaid-console-errors
Open

Fix mermaid console errors#124
paulbrimicombe wants to merge 1 commit into
bbc:mainfrom
paulbrimicombe:fix-mermaid-console-errors

Conversation

@paulbrimicombe

Copy link
Copy Markdown
Contributor

🧐 What?

Currently when a Mermaid diagram is included in the page the following errors can be seen in the console:

Uncaught ReferenceError: mermaid is not defined
Uncaught TypeError: Cannot read properties of undefined (reading 'mermaid')

Screenshot:

image

This is because the mermaid.min.js bundle is imported as an ES Module (using type="module") but it is expecting to be imported as a "classic script". When imported as a module, the mermaid global object fails to be set and the mermaid bundle throws an error. All diagrams still render successfully, however.

An ESM version of Mermaid does exist but is difficult to use because:

  • The NPM package does not include a single-file ESM bundle — it's split across multiple files which would all need to be uploaded to S3
  • The CDN distribution does have a single-file ESM bundle but using this makes version management more difficult than using the NPM package (and would mean that tools like dependabot wouldn't be able to monitor vulnerabilities for the Mermaid dependency).

🛠 How

Removing the type attribute from the Mermaid <script> tag eliminates the console errors

@paulbrimicombe
paulbrimicombe requested a review from a team as a code owner July 21, 2026 08:02
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.

1 participant