-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Support ESM config file #5379
Comments
Can you explain exactly what you mean? I'm not able to understand:
Note Docusaurus is not compatible with the latest versions of remark/rehype. |
Here's an unsuccessful version bumping for Build is failing because It seems I'm not so familiar with this, but I wonder why would ESM import fail when I'm on Node v16? The code below uses
|
I don't know. Try running
Is it really Docusaurus? Make sure to replace Then again if I'd try to add a But it's likely that we'll need to add proper support for ESM in all packages |
It took me much longer than I thought to make But in the end you can't
Some day we are going to make all the packages ESM (by changing the TS target), but that will be when we drop Node v10 support (which I hope is soon, it's not even maintained anymore) |
@slorber @Josh-Cena Thanks for your responses. I updated my question to include more details. As you guys said it seems like Docusaurus just doesn't have support for the config being es6 currently. If there are compatible versions of remark/ rehype plugins, is that listed in the docs somewhere that I just missed? |
@lukejgaskell I don't know if the doc's wrong in this sense, but at least here we did explicitly state the version: https://docusaurus.io/docs/next/markdown-features/math-equations#configuration. I guess it makes sense to update the doc section you mentioned and explicitly warn that the version matters. For your question—https://github.com/remarkjs/remark-images/releases/tag/3.0.0 |
Yes, we should warn in the doc that users must install plugin versions compatible with cjs (not the latest). Unfortunately, we can't really maintain an exhaustive compatibility table. @Josh-Cena we already dropped Node.js 10: https://docusaurus.io/docs/next/installation#requirements But not sure Node 12 exp support is good enough and in sync with Node 16 support so I'd rather wait a bit more and drop Node 12 too before attempting significant changes, otherwise we may need to support both cjs/esm at the same time and it may be more painful. |
After #5812, we are in a good position to consider how we are going to support ESM in our code base. TypeScript 4.5 is also focusing on prioritizing ESM support, so maybe we can wait till its stable release to test out how that can aid us in the migration. |
Same issue here. I'm trying to follow the MDX plugin guide in Docusaurus Doc and create a plugin ESLint popups up and tell me:
And the latest Downgrade to V2 solved the issue.
|
|
Just ran into this today when trying to use remark-directive. It's a pretty sharp edge for new folks like me :) |
@cprice404 remark-directive is only for MDX 2 (Docusaurus v3): The PR (#8288) has only been merged recently (you can try a canary version) and uses remark-directive by default this is how we implement admonitions now) so you don't need to add it manually. If you want to use ESM remark plugins, now or in the future you can turn your config into an async function: module.exports = async function createConfig() {
const plugin = (await import('some-remark-esm-plugin')).default;
return {
// ...
};
} It's not convenient but it should unlock you until we support ESM in the config file. |
ah! that's really helpful, thanks! |
📚 Documentation
Remark and Rehype are ES6 Modules only now and the documentation imports them as CommonJS modules.
Page that that does work as described: https://docusaurus.io/docs/next/markdown-features/plugins
The documentation just says to install those packages
and import them as
The remark-images package is ESM only and is not able to be required. The
docusaurus.config.js
is a CJS module and can't include that package.If it is just an older version of those plugins need to be specified, then that makes sense, but might be nice to have in the docs.
Edit: added more details
The text was updated successfully, but these errors were encountered: