Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Docusaurus 3.6 #294

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

MattiasBuelens
Copy link

@MattiasBuelens MattiasBuelens commented Nov 12, 2024

Docusaurus 3.6 introduced some changes which broke the OpenAPI plugin (see #293). This PR fixes that issue, by using the new createMDXLoaderItem API to create the rule for @docusaurus/mdx-loader (see facebook/docusaurus#10450) by adding the missing siteDir property to the mdx-loader options.

This PR also adds support for Docusaurus Faster (facebook/docusaurus#10556).

Fixes #293

Copy link

netlify bot commented Nov 12, 2024

Deploy Preview for docusaurus-openapi ready!

Name Link
🔨 Latest commit c57099f
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-openapi/deploys/673b79b6cd214f00083663a8
😎 Deploy Preview https://deploy-preview-294--docusaurus-openapi.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 site configuration.

},
},
].filter(Boolean),
use: [getJSLoader({ isServer }), mdxLoaderItem].filter(Boolean),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey

This is not really a public API (for now) 😅 , I may refactor this on a minor version.

I'm not sure what was the error in the first place since the author didn't share the full stacktrace, and how this fixes it 🤔

Note: with Docusaurus v3 you don't need to put a js loader in front of MDX anymore, the output of MDX is already in a form your bundler can understand unless you do anything fancy in MDX docs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what was the error in the first place since the author didn't share the full stacktrace, and how this fixes it

In terms of the original error, this PR was opened to address #293

Here's an example stacktrace:

Module build failed (from ./node_modules/@docusaurus/mdx-loader/lib/index.js):
TypeError: The "from" argument must be of type string. Received undefined
    at validateString (node:internal/validators:162:11)
    at Object.relative (node:path:1194:5)
    at aliasedSitePath (/home/chris/dev/my-website/node_modules/@docusaurus/utils/lib/pathUtils.js:85:51)
    at loadMDX (/home/chris/dev/my-website/node_modules/@docusaurus/mdx-loader/lib/loader.js:62:77)
    at async Object.mdxLoader (/home/chris/dev/my-website/node_modules/@docusaurus/mdx-loader/lib/loader.js:156:24)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original error happened because the OpenAPI plugin wasn't passing the siteDir option to mdx-loader. Apparently that wasn't being used before Docusaurus 3.6 so the plugin still worked, but now it's actually being used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the PR to no longer use createMDXLoaderItem.

Note: with Docusaurus v3 you don't need to put a js loader in front of MDX anymore, the output of MDX is already in a form your bundler can understand unless you do anything fancy in MDX docs.

Thanks for the tip! I've removed the extra JS loader. 👍

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm I see thanks.

siteDir is a required loader option before v3.6, but maybe it wasn't failing before. Unfortunately since you don't use the types you didn't know your code didn't typecheck.

I think it could actually be better if you use createMDXLoaderItem to ensure that no attribute is missing if we add more of them in the future. Unfortunately we can't guarantee this won't happen in a minor version 😅

I think in the future we'll provide some kind of public API provided by the plugin lifecycle such as getMDXLoader(), similar to what you already used with getJSLoader.

If we introduce this new API, we may still keep createMDXLoaderItem() so it should be fine to use it. You already use non-public APIs anyway 😅

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, we weren't using the proper types. Woops! 😅

I've added satisfies MDXLoaderOptions to the options object, so these kinds of errors can be caught more quickly in the future. Then createMDXLoaderItem() can still be non-public API for now. 👍

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.

TypeError: The "from" argument must be of type string. Received undefined with Docusaurus >=3.6.0
3 participants