-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
ERR_REQUIRE_ESM
when requiring .eslintrc.js
#12319
Comments
This is from the change that disallows |
The ideal theoretical fix would be for your eslint file to be loaded as an ES module itself since the package boundary is supposed to have all That is,
|
Irrelevant now: Could the eslint config be put into |
Thanks for bringing this to the team's attention. We're tracking nodejs/modules#388 and would love to work with the wider tooling community to figure out how we as a community want to handle this, since it's going to affect so many projects. It would be great to standardize on something to lower the barrier for entry for using all these tools. |
I have a question. Is there a way that loads ES module files synchronously? Do we have to remove sync API (e.g. |
I second @guybedford’s suggestions for how to make eslint compatible with /app/.eslintrc.js
/app/package.json # Main package.json for app, with "name", "main", "dependencies", etc.
/app/src/package.json # Just { "type": "module" }
/app/src/... # Rest of app in here Since Presumably many projects using ES module syntax today already have their code in a subfolder like Obviously it’s more ideal to have only one |
Generally speaking - no. So using
|
Note that simply changing the eslintrc.js won't work if you have any node plugins / configs written as eslintrc.js this error still happens, and you can stay on node v12.10.0 until a solution has been found for this. |
Not speaking for the team here, this is just my own 2 cents. When considering supported file types, module types, runtimes, etc., I think ESLint needs to consider those at two different levels:
ESLint has a philosophy of trying not to favor one runtime over others. I understand that philosophy as applying to "Code being linted/processed". We have features like On the other hand, ESLint itself runs on Node.js. That is a specific decision we made-- we don't run(*) on browsers, RhinoJS, or other runtimes. We are a Node package. So, for an issue like this that is about the execution of ESLint from Node, I think we need to follow Node.js's lead as much as we reasonably can and try to support different Node module styles, within reason. (This is not the same as saying we need to make ESLint async so it can be imported as an ES module itself.) So based on that, if .cjs is official/not experimental (or will be very soon), I think we need to support it by allowing (*) Okay, we have webpack/browserify which creates a browser implementation, but that is not officially supported. |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
Latest discussion is happening here: eslint/rfcs#43 |
* Fix: ES module compatibility (fixes #12319) In ES module packages w/ "type": "module" defined treat all .js files as ES modules. CommonJS files contained in an ES module package should use the .cjs extension. * Fix Documentation * Add Tests * Fix Lint Error
What about backporting this to a latest stable release of eslint? |
Tell us about your environment
macOS, node v12.11.0
What parser (default, Babel-ESLint, etc.) are you using? default
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
I've set
"type": "module"
in thepackage.json
of my project and runeslint
What did you expect to happen?
No internal errors in
eslint
What actually happened? Please include the actual, raw output from ESLint.
Are you willing to submit a pull request to fix this bug?
Maybe... although, it would require time to investigate this and learn the codebase first.
The text was updated successfully, but these errors were encountered: