eslint-config
eslint-config copied to clipboard
[Feature Request] disable use globals var `__dirname` `__filename` in nodejs esm mode
Clear and concise description of the problem
disable use globals var __dirname
__filename
in nodejs esm mode
These CommonJS variables are not available in ES modules. https://nodejs.org/api/esm.html#no-__filename-or-__dirname
Suggest use import.meta.filename
import.meta.dirname
instead
Link: eslint-community/eslint-plugin-n#164
Suggested solution
N/A
Alternative
No response
Additional context
No response
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guide.
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@antfu I'm very sorry to disturb you. I hope this doesn't cause any inconvenience for you. I would like to know if this feature request is easy to implement. Is it possible that it will be supported?
I'd be happy to disallow __dirname et al., but I am not sure if we should recommend import.meta.filename
as it would be still runtime-specific. I usually use new URL('../', import.meta.url)
to make it work cross platform.
Sorry, I am not an experienced front-end developer. I trust that the usage you recommended is surely better.
The idea behind this feature request originated from a bug I encountered during a migration from CommonJS to ESM.
Ref: https://github.com/Kerwin1202/chatgpt-web/issues/405
I think currently I don't want to have a strict rule for that - feel free to disable it on userland.