-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Migration to ES Modules #6520
Comments
Yes !!!! +1 ! Error was something like
and
|
@iPurpl3x Your problem is probably not because of ESM, because |
I ran Outdated dependencies
Mostly Sindre Sorhus packages and MDX ones |
This is just going to get worse with time, @Josh-Cena Thanks for the great work, hopefully we can get Docusaurus using ESM soon. |
sindre is working on converting his packages to pure ESM, see https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c also, the latest |
What do you mean by "does not work"? How do you run it and how do you see it not working exactly? It seems to work for me |
TS 4.7 seems promising: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7-beta/#ecmascript-module-support-in-node-js We should be able to investigate after that |
Yes, also great to have "exports" field support! |
Update: the fix that adds support for the |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
I hit an error after migrating to ES modules due to generation of client-modules.js which uses require:
The V3 announcement made me think I should be switching to modules. I might be doing something silly, not a JS expert. |
@samos123 this issue is about running ES modules natively inside the Node.js runtime (or publishing ESM package), not about public-facing features supporting ESM. We already support ESM syntax in client modules (our own site use it for a while if you look for an example), and v3 brings ESM support for site config, sidebars etc... If you encounter a bug, please open a dedicated issue. "I hit an error" without any extra information is not going to help us in any way help you. |
homotechsual from the Discord server told me to post this bug report here, sorry if this is off-topic. Docusaurus does not seem to support the "type" field in the "package.json" file. Subsequently, it seems impossible to use ESM with Docusaurus. (To be clear, you can have an ESM config file, but the project itself can obviously not be ESM.) Here are steps to showcase the problem:
This seems very unexpected, as it was my understanding that the
|
@Zamiell |
Have you read the Contributing Guidelines on issues?
Motivation
I did a very naïve attempt to migrate to ESM in #5816, but I far underestimated the difficulty in pushing it through. After some pondering, I think this should be rolled out progressively.
Status of ESM
ESM is a new type of Node modules system, replacing the old common JS system (
require
+module.exports
). For the engine, the parsing goal is different ("module" or "script"), so a file needs to be determined as ESM or CJS before executing it, either through the.mjs
extension or through the"type": "module"
entry in the nearest package.json.If a file is ESM, it can import from other ES modules. However, it may not be able to import all CJS modules, depending on how the CJS module is structured, because exported symbols, per the ES spec, need to be lexically determined, while CJS can be far more dynamic.
If a file is CJS, it can't import ESM modules, unless the
await import()
dynamic import is used. However, this is against the norm of how most modules are imported. This effectively means as soon as a considerable number of the dependencies are ESM, we have to migrate ourselves.Many packages on NPM are now ESM-only, most notably the packages by Sindre Sorhus, and MDX v2, which is the pillarpost of our architecture.
Benefits
Blockers
--experimental-specifier-resolution=node
and keep the old resolutionimport-fresh
to bypass cache and always import fresh modules for hot reloading, etc. But ES Modules don't expose caching manipulation yetutils
andlogger
)Actions needed
__filename
and__dirname
. These globals don't exist in the ESM scope, replaced by theimport.meta.url
target: 'nodenext'
in the tsconfig.index.js
name and the.js
extension to be explicit."type": "module"
in our package.json.Plan
docusaurus.config.js
andsidebars.js
can be allowed in ESM once we figure out how to bypass cache and fresh-import ESMutils
,utils-validation
,logger
. They should always be distributed as dual-package because plugin authors are likely to import them as CJS.import-fresh
. Migration to ESM means we can import both CJS and ESM plugin modules withawait import
. However, because users only interact with the core through its own CLI, we don't have to care about others importing this.import-fresh
in the core), because they have to be imported as ESM.Related issues/PRs
If an issue or PR is related to the ESM migration process, please link to this meta-issue and we will add it to the list below for tracking purposes.
The text was updated successfully, but these errors were encountered: