Skip to content

Docusaurus v3 markdown links don't resolve correctly from index pages during build step when trailingSlash is set to false #9720

Description

@maxweisel

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.
  • I have read the console error message carefully (if applicable).

Description

Hey all,

(My original issue was closed because my repro didn't match /exactly/. This one matches /exactly/.)

I've got a fresh docusaurus v3 project with trailingSlash set to false in the config, and I noticed that when it resolves relative links from markdown files, it does it incorrectly if the file is a readme.md file within a folder (acting as an index).

In short if you have the following docs folder structure:

docs/test/readme.md
docs/cool-page.md

and test/readme.md contains the following markdown:

[Cool page](../cool-page.md)

running build will generate the following error:

  Exhaustive list of all broken links found:
  - Broken link on source page path = test:
     -> linking to ../cool-page (resolved as: /cool-page)

Despite the error saying it was resolved as /cool-page it is in fact not.

Interestingly, if I switch the link to ./cool-page (removing the ../). It works correctly. My guess is that rather than using the path of the readme.md file when resolving a relative path, it's using the location of the folder that contains it (in this case it assumes the links are coming from a file at the path ./test instead of a file at ./test/readme.md.

Max

Reproducible demo

https://codesandbox.io/p/devbox/runtime-pine-84xm8d

Steps to reproduce

run npm run build on the playground

Expected behavior

It builds correctly without errors

Actual behavior

Exhaustive list of all broken links found:

  • Broken link on source page path = test:
    -> linking to ../cool-page (resolved as: /cool-page)

Your environment

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

Self-service

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error in the Docusaurus core causing instability or issues with its executionclosed: duplicateThis issue or pull request already exists in another issue or pull request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions