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

Support ESM #504

Open
nirtamir2 opened this issue Nov 25, 2023 · 6 comments
Open

Support ESM #504

nirtamir2 opened this issue Nov 25, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@nirtamir2
Copy link

nirtamir2 commented Nov 25, 2023

Hi!
Thank you for creating this tool!
I would like to create ESM only ESLint plugin, and this rule tries to require stuff inside so it's not compatible
I would like it to work with ESM.

❯ pnpm run update:eslint-docs

> eslint-doc-generator

require() of ES Module ***/lib/index.mjs not supported.
Instead change the require of ***/lib/index.mjs to a dynamic import() which is available in all CommonJS modules.

Thanks!

@bmish
Copy link
Owner

bmish commented Nov 25, 2023

Do you have a public example to link to? Is your plugin compiled to CJS? Or are you using flat config? (#376).

@bmish bmish added the enhancement New feature or request label Nov 25, 2023
@nirtamir2
Copy link
Author

nirtamir2 commented Nov 26, 2023

Thank you for your fast response!

Do you have a public example to link to? Is your plugin compiled to CJS? Or are you using flat config? (#376).

https://github.com/nirtamir2/eslint-plugin-default-import-name

nirtamir2/eslint-plugin-default-import-name@7c545cf - this is the commit I converted to ESM only. I did not want to lose the eslint-doc-generator so I reverted it later

@bmish
Copy link
Owner

bmish commented Nov 26, 2023

With ESM, you still have a build command and compiled CJS output, right? If this is the case, then the solution is normally to just ensure the build runs before running eslint-doc-generator: https://github.com/bmish/eslint-doc-generator#build-tools

{
  "build": "tsc",
  "update:eslint-docs": "npm run build && eslint-doc-generator"
}

@ljharb
Copy link

ljharb commented Nov 26, 2023

Not if they’re using native ESM.

@nzakas
Copy link

nzakas commented Jun 19, 2024

@bmish I ran into this with a new native ESM project. Because "main" in package.json points to an ESM file, I end up with this error.

You can probably somewhat account for this by checking "exports" field for a CommonJS entrypoint, though at this point, I don't know that you can rely on packages to continue publishing CommonJS entrypoints.

@ljharb
Copy link

ljharb commented Jun 19, 2024

Those that stop doing so almost universally leave the majority of their users stuck on the last version to do so, so i think that's still something that can be relied on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants