Skip to content

Zero-width space in mdx file path => build fails due to hash mismatch #12005

Open

Description

@zhang-brook

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
    (because of the network problem, I can't work with CodeSandbox and StackBlitz, but it can reproduce in the clean new project)
  • I have read the console error message carefully (if applicable).

Description

  1. In a fresh Docusaurus project on Windows using npm, creating docs/contribute/index.mdx works fine.
  2. However, moving that same file into docs/contribute/vulnerability-report/index.mdx causes the build to fail.
    Image
  3. Renaming the folder vulnerability-report to foo-bar resolves the issue.
    Image
  4. Moving the file back to docs/contribute/index.mdx also resolves it. The problem occurs with both .mdx and .md extensions.
  5. Moving the file back to docs/contribute/vulnerability-report/index.mdx again, the build fail again.

Reproducible demo

https://github.com/coder-xiaomo/docusaurus-bug-minimal-repro/commits/main/

Image

Steps to reproduce

  1. Create a new Docusaurus project using npm on Windows:

    npx create-docusaurus@latest my-website classic --typescript
    cd my-website
    npm install
  2. Create a file docs/contribute/index.mdx with any content (e.g., # Test).

  3. Run npm start – the site builds successfully and the doc displays at /docs/contribute.

  4. Stop the server. Move the file into a new subdirectory vulnerability-report:

    mkdir docs\contribute\vulnerability-report
    move docs\contribute\index.mdx docs\contribute\vulnerability-report\index.mdx

    Then run npm start – build fails (error details below).

  5. Stop the server. Clean the cache and dependencies:

    rmdir /s /q .docusaurus
    rmdir /s /q node_modules
    npm install

    After reinstallation, run npm start again – the error still occurs.

  6. Stop the server. Rename the vulnerability-report folder to foo-bar:

    move docs\contribute\vulnerability-report docs\contribute\foo-bar

    Run npm start – the build now works correctly.

  7. Stop the server. Move the file back to docs/contribute/index.mdx:

    move docs\contribute\foo-bar\index.mdx docs\contribute\index.mdx

    Run npm start – the build works correctly again.

  8. (Optional) Repeat the same steps using a .md file instead of .mdx – the problem is reproducible exactly the same way.

Expected behavior

The build should succeed, and the doc should be accessible at /docs/contribute/vulnerability-report without any hash mismatch. Deleting .docusaurus and node_modules should not be necessary for a correct build.

Actual behavior

When the file is located at docs/contribute/vulnerability-report/index.mdx, the build fails with a module resolution error:

× Cannot find module '@site/.docusaurus/docusaurus-plugin-content-docs/default/site-docs-contribute-vulnerability-report-index-mdx-e58.json' for matched aliased key '@site'
Image

Meanwhile, inside .docusaurus/docusaurus-plugin-content-docs/default/, the actual generated file is:

site-docs-contribute-vulnerability-report-index-mdx-b66.json

Notice the hash mismatch: looking for -e58 but the file exists with -b66.

Image

Your environment

Self-service

  • I'd be willing to fix this bug myself. (but I am not sure where the root cause is. If the root cause was found, maybe I can create an pull request to fix it)

Activity

  1. added
    bug
    status: needs triage
    on May 9, 2026
  2. zhang-brook commented on May 14, 2026

    @zhang-brook
    ContributorAuthor

    I have now identified the root cause. My file directory contains two invisible characters.
    Image

    In Docusaurus v3, these invisible characters were ignored and the build worked normally. After upgrading to v4, it seems that when generating files and when locating files by filename, the presence of these special characters causes inconsistent hashes in the generated docs-<hash>.json files – the hash used to look up the file does not match the actual hash of the generated file. This results in a build failure.

    @slorber I suggest adding validation for special/invisible characters in file paths.

    In this case, the problematic folder name (contains invisible characters):
    [vulnerability-report​​] (between t and ])
    The correct folder name (no invisible characters):
    [vulnerability-report]

  3. danyalahmed1995 commented on May 20, 2026

    @danyalahmed1995
    Contributor

    Hey I tried to reproduce this on my system.

    Setup:

    • Windows 10
    • Node v24.14.1
    • Docusaurus 3.10.1.

    The interesting part is that the failing folder name is not plain ASCII. In the repro repo, the folder is:

    vulnerability-report<U+200B><U+200B>

    so there are two trailing zero-width spaces after report.

    The build writes:

    site-docs-contribute-vulnerability-report-index-mdx-b66.json

    but the MDX metadata import asks for:

    site-docs-contribute-vulnerability-report-index-mdx-e58.json

    I also checked a fresh controlled project: plain docs/contribute/vulnerability-report/index.mdx passes, but the same path with U+200B reproduces the mismatch. So this looks less like a route/sidebar/cache issue and more like hidden Unicode path handling between docs metadata generation and the MDX loader metadata import.

    I think this should be addressed , maintainers feedback would be appreciated . I will see if i can open a PR for it

  4. danyalahmed1995 commented on May 21, 2026

    @danyalahmed1995
    Contributor

    In Docusaurus v3, these invisible characters were ignored and the build worked normally. After upgrading to v4, it seems that when generating files and when locating files by filename, the presence of these special characters causes inconsistent hashes in the generated docs-.json files – the hash used to look up the file does not match the actual hash of the generated file. This results in a build failure.

    In this case, the problematic folder name (contains invisible characters):
    [vulnerability-report​​] (between t and ])
    The correct folder name (no invisible characters):
    [vulnerability-report]

    To narrowing this down to the invisible characters. I opened #12044 with a small fix for this.

    I checked the repro more deeply and confirmed the failing folder is:

    vulnerability-report<U+200B><U+200B>

    with two trailing zero-width spaces.

    The reason I did not go with validation-only is that Docusaurus v3 apparently handled this, and the actual failure is not just “invalid path exists”. The build writes metadata using one source string:

    site-docs-contribute-vulnerability-report-index-mdx-b66.json

    but the MDX loader imports metadata using another:

    site-docs-contribute-vulnerability-report-index-mdx-e58.json

    So the PR makes the MDX metadata import resolve back to the loaded docs source before hashing, keeping both sides in sync.

    I also added a guard for ambiguous cases where paths only differ by U+200B, so Docusaurus reports the ambiguity clearly instead of silently picking the wrong metadata source.

    The normal ASCII path still works, and the zero-width-space repro now passes in the controlled/manual checks.

  5. slorber commented on May 21, 2026

    @slorber
    Collaborator

    In Docusaurus v3, these invisible characters were ignored and the build worked normally.
    After upgrading to v4...

    FYI, Docusaurus v4 doesn't exist yet. Are you using a canary version? It's unclear which version worked, and when it stopped working. Please share valid and stable version numbers so we can look at the diff.


    Here's an end-to-end repro PR with this problem, the goal is to make this pass with a good solution: #12052

    Agree that there is a hash mismatch somewhere, but I don't find the PR above very attractive and generic. The problem is likely to affect all our content plugins, and may also affect third-party plugins, so a generic solution would be better.

    Before implementing anything, we must understand what the hashes are different.

  6. danyalahmed1995 commented on May 21, 2026

    @danyalahmed1995
    Contributor

    Before implementing anything, we must understand what the hashes are different.

    So I traced the two hash inputs locally with the dogfood repro.

    Interestingly metadata writer hashes the loaded docs source, which preserves both zero-width spaces:

    @site/_dogfooding/_docs tests/tests/zero-width-spaces/vulnerability-report<U+200B><U+200B>/index.mdx

    That produces the written metadata file:

    site-dogfooding-docs-tests-tests-zero-width-spaces-vulnerability-report-index-mdx-dfd.json

    The MDX loader/import path without the fix comes from the loader resourcePath, and in this repro it has only one zero-width space:

    @site/_dogfooding/_docs tests/tests/zero-width-spaces/vulnerability-report<U+200B>/index.mdx

    That produces the missing imported file:

    site-dogfooding-docs-tests-tests-zero-width-spaces-vulnerability-report-index-mdx-9b6.json

    So the mismatch is not just “same visible path, random hash.” The writer side is hashing the loaded docs source with two U+200Bs, while the loader/import side is hashing a path with one U+200B.

    With the dogfood repro added, disabling the resolution makes yarn build:website:fast fail with the missing ...9b6.json import, and restoring it makes the same command pass.

  7. changed the title [-][BUG] Build fails when creating `docs/contribute/vulnerability-report/index.mdx`, but creating the file in another directory does not cause the error (very weird but reproducible)[/-] [+]Zero-width space in mdx file path => build fails due to hash mismatch[/+] on May 22, 2026
  8. removed
    status: needs triage
    on May 22, 2026
  9. slorber commented on May 22, 2026

    @slorber
    Collaborator

    This is likely a Rspack bundler issue.

    My repro fails under Rspack, works if I turn off these 2 flags and build with Webpack:

    {
      rspackBundler: false,
      rspackPersistentCache: false,
    }

    We are going to upgrade to Rspack v2 asap, see if this is fixed, and if not we'll see how to send them a minimal repro.

  10. danyalahmed1995 commented on May 22, 2026

    @danyalahmed1995
    Contributor
    Confirmed locally with the exact #12052 repro.
    
    Default Rspack config fails with missing metadata imports for the zero-width-space paths. With only:
    rspackBundler: false,
    rspackPersistentCache: false,

    and a clean build, the same repro passes.

    So I agree this looks Rspack-specific rather than a docs metadata issue by itself.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions