Skip to content

Support onBrokenMarkdownImages, ability to not fail the build in case of a broken image path #11219

Closed

Description

@crackleeeessyp

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

Docusaurus build fails when referencing root-domain images via relative paths, despite setting baseUrl and onBrokenMarkdownLinks: "warn".

settings:

baseUrl: https://test/websites/my-docusaurus-site

Desired image URL: https://test/images/qr.png

Markdown reference: ![qrcode](../../../images/qr.png)

Error:

Module build failed (from ../node_modules/@docusaurus/mdx-loader/lib/index.js):
Error: MDX compilation failed for file "docs\intro.md"
Cause: Image ../../images/qr.png used in docs/intro.md not found.
Details:
Error: Image ../../images/qr.png used in docs/intro.md not found.
    at ensureImageFileExist (\node_modules\@docusaurus\mdx-loader\lib\remark\transformImage\index.js:84:15)
    at async getImageAbsolutePath (\node_modules\@docusaurus\mdx-loader\lib\remark\transformImage\index.js:106:5)
    at async processImageNode (\node_modules\@docusaurus\mdx-loader\lib\remark\transformImage\index.js:129:23)
    at async Promise.all (index 1)
    at async \docs\node_modules\@docusaurus\mdx-loader\lib\remark\transformImage\index.js:148:9
    at compileToJSX (node_modules\@docusaurus\mdx-loader\lib\utils.js:93:15)
    at async loadMDX (\node_modules\@docusaurus\mdx-loader\lib\loader.js:22:20)
    at async Object.mdxLoader (\node_modules\@docusaurus\mdx-loader\lib\loader.js:156:24)

I try to use ![qrcode](/images/qr.png), however, it does not point to the website root, so I can only use ../../../images/qr.png to make sure its url is https://test/images/qr.png.

Any idea to solve this problem?

Reproducible demo

No response

Steps to reproduce

Simple docusaurus starter project can produce above issue

Expected behavior

Ignore validations in markdown file because I already set onBrokenMarkdownLinks to warning

Actual behavior

It still validate url in markdown for images

Your environment

  • Public source code:
  • Public site URL:
  • Docusaurus version used:
  • Environment name and version (e.g. Chrome 89, Node.js 16.4):
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS):

Self-service

  • I'd be willing to fix this bug myself.

Activity

  1. added
    bug
    status: needs triage
    on May 30, 2025
  2. slorber commented on May 30, 2025

    @slorber
    Collaborator

    It's impossible to help without a docusaurus.new repro, we don't even know where your image file is exactly. Please provide a repro and respect our issue template, providing all the required information. I'll reopen if a repro is provided and we can clearly validate it's a bug.


    onBrokenMarkdownLinks has no effect on markdown images. Images are not links. We validate images by default but if you want an escape hatch you can use ![qrcode](pathname:///whatever/images/qr.png), in which case we output the path provided directly in the HTML markup. If the image doesn't exist at the path you provide, we can't do anything about it, it's out of the scope of Docusaurus.

  3. added
    closed: invalid
    and removed
    status: needs triage
    on May 30, 2025
  4. scooby359 commented on Jun 3, 2025

    @scooby359

    A markdown image using the syntax ![qrcode](../../../images/qr.png) is still using a link as the image source. Would expect onBrokenMarkdownLinks value to be respected here too.

  5. slorber commented on Jun 4, 2025

    @slorber
    Collaborator

    A markdown image is not a markdown link, despite using a similar syntax. Similarly, a <a href""> is not the same as <img src="">, despite both using an URL.

    We are more likely to introduce a new onBrokenMarkdownImages API rather than emit image URLs in onBrokenMarkdownLinks. Would that be helpful?

    (in the future, all these APIs are likely to accept a callback and not just a severity level)

  6. scooby359 commented on Jun 4, 2025

    @scooby359

    Yes, handling these broken elements is important to the user experience - it's handled for links and anchors, so reasonable for users to expect it would handle images with the same problem too.

    My experience of this is that I'm looking at migrating an Obsidian markdown project to Docusaurus so it can be web hosted, but this will be a gradual project as content needs to be verified as safe to publish. In the meantime, this causes broken images. Currently, Docusaurus refuses to build at all where image paths are broken, so it's not fit for use for my project.

    Having Docusaurus be able to handle broken image paths would make it easier to migrate projects into Docusaurus.

  7. crackleeeessyp commented on Jun 6, 2025

    @crackleeeessyp
    Author

    How about reopen this issue, since it will block build process if the resources not in the local, and wish there is another configuration to make it work.

  8. slorber commented on Jun 6, 2025

    @slorber
    Collaborator

    I'm going to reopen and consider this a feature request to add onBrokenMarkdownImages


    But you are not blocked, if the resource does not exist locally, you can:

    • make the resource exist locally
    • create a remark plugin to rewrite the URL to another URL that exists
    • prefix the resource with pathname:// so that we leave your resource URL unchanged (escape hatch, but you might depoy broken images to production)
    • use a fully qualified URL instead of a path (https://example.com/myimage.png instead of /myimage.png)

    Unlike links, we use require('./image/path.png') for images, so if we stop throwing for such images, then we'll have to output your path as is, and no image will be processed by the bundler (like we usually do for all local images).

  9. reopened this on Jun 6, 2025
  10. changed the title [-]onBrokenMarkdownLinks not work for image links in mdx file[/-] [+]Support `onBrokenMarkdownImages`, ability to not fail the build in case of a broken image path[/+] on Jun 6, 2025
  11. added
    feature
    and removed
    bug
    closed: invalid
    on Jun 6, 2025
  12. slorber commented on Jun 6, 2025

    @slorber
    Collaborator

    Yes, handling these broken elements is important to the user experience - it's handled for links and anchors, so reasonable for users to expect it would handle images with the same problem too.

    My experience of this is that I'm looking at migrating an Obsidian markdown project to Docusaurus so it can be web hosted, but this will be a gradual project as content needs to be verified as safe to publish. In the meantime, this causes broken images. Currently, Docusaurus refuses to build at all where image paths are broken, so it's not fit for use for my project.

    Having Docusaurus be able to handle broken image paths would make it easier to migrate projects into Docusaurus.

    Honestly I'm not sure to understand your point.

    Docusauus protects you from deploying a site with broken images. If you migrate, this is a nice feature that permits to explicitly tell you that you may not have migrated all your images properly. If you use this flag, you will be able to deploy, but your site will show missing images, and I'm not sure it's better than forcing you to ensure the images are present. It's a DX feature to allow you to do so, not an UX feature (because website visitors will see broken images).


    Edit: someone reported a case similar to yours here and this kind of makes sense, you may want to avoid the error overlay in dev, and be able to deploy a site with broken images in a staging environment.

  13. slorber commented on Jun 11, 2025

    @slorber
    Collaborator

    Until we add support for this, here are some ideas you can try implementing in userland.

    #11247 (reply in thread)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions