Skip to content

fix(mdx-loader): skip asset transformation for directory links with dots#12037

Closed
Dharya-dev wants to merge 2 commits into
facebook:mainfrom
Dharya-dev:fix/directory-dot-link-build-error
Closed

fix(mdx-loader): skip asset transformation for directory links with dots#12037
Dharya-dev wants to merge 2 commits into
facebook:mainfrom
Dharya-dev:fix/directory-dot-link-build-error

Conversation

@Dharya-dev
Copy link
Copy Markdown

Summary

Fixes a build error when a Markdown link points to a local directory that has a dot in its name (e.g., [link](../directory-with.dot/)).

Resolves #11940

Problem

path.extname("directory-with.dot/") returns ".dot", which is truthy. The transformLinks remark plugin interprets this as a file with an asset-like extension and calls toAssetRequireNode(). Since the target is actually a directory (not a file), Webpack's require() fails with:

Module not found: Error: Can't resolve './../directory-with.dot'

Fix

After getLocalFileAbsolutePath resolves the target path, I added a check using fs.stat() to see if the path is a directory. If it is, the asset transformation is skipped entirely and the link is left unchanged — which is the correct behavior for directory links.

Changes

  • packages/docusaurus-mdx-loader/src/remark/transformLinks/index.ts — Added fs.stat() directory check before toAssetRequireNode()
  • packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/index.test.ts — Added two test cases covering directory links with dots (with and without trailing slash)
  • __fixtures__/directory-with.dot/index.md — Test fixture directory

Test Results

 ✓ packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/index.test.ts (12 tests) 169ms

 Test Files  1 passed (1)
      Tests  12 passed (12)

Let me know if any changes are needed!

When a Markdown link targets a local directory that has a dot in its name
(e.g., `[link](../directory-with.dot/)`), path.extname() returns a truthy
value (`.dot`), causing the transformLinks plugin to incorrectly treat it
as a file asset. This results in a failed require() call and a broken build.

This fix adds a directory check via fs.stat() after resolving the local
path. If the path is a directory, the asset transformation is skipped and
the link is left as-is.

Closes facebook#11940
@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented May 18, 2026

Hi @Dharya-dev!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@netlify
Copy link
Copy Markdown

netlify Bot commented May 18, 2026

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 9890260
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/6a0b74e620cd2e0008fb3404
😎 Deploy Preview https://deploy-preview-12037--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Dharya-dev
Copy link
Copy Markdown
Author

Dharya-dev commented May 18, 2026

Closing in favor of @thanasis2028's PR #11944. Since they did the work first and I am closing the duplicate PR and offer support on the original one. Good luck getting it merged!

@Dharya-dev Dharya-dev closed this May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Links to local directories with dots in filename break docusaurus build

1 participant