Bug: [flat config] `.mjs` extension for config file
See original GitHub issueEnvironment
Environment Info:
Node version: v19.1.0 npm version: v8.19.3 Local ESLint version: v8.28.0 (Currently used) Global ESLint version: Not found Operating System: darwin 22.1.0
What parser are you using?
Default (Espree)
What did you do?
My npm package is commonjs, with .js
extensions, alongside ESM with .mjs
extensions for running tests. Running npx eslint .
results in Node failing to parse the configuration file, as it assumes it to be commonjs.
What did you expect to happen?
The config file should only support a .mjs
extension (eslint.config.mjs
) to avoid this problem since Node will always execute it as ESM regardless of the type
field defined in package.json
.
What actually happened?
(Shortened)
Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
...
eslint.config.js:1
export default [
^^^^^^
SyntaxError: Unexpected token 'export'
Participation
- I am willing to submit a pull request for this issue.
Additional comments
No response
Issue Analytics
- State:
- Created 10 months ago
- Reactions:5
- Comments:17 (9 by maintainers)
Top Results From Across the Web
ES6 Test Match in configuration file ignoring .mjs extension ...
If you add "mjs" to moduleFileExtensions config, then the mjs file extension will be matched. { verbose: true, projects: [ { displayName: " ......
Read more >ESLint's new config system, Part 2: Introduction to flat config
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >How to correctly configure the parser & plugins with ESLint's ...
Im using flat config with typescript. Heres what I think are the important parts of the config:
Read more >K13408: Overview of single configuration files (11.x - 15.x)
A single configuration file (SCF) is a flat, text file that contains all of the objects that compose the BIG-IP configuration.
Read more >Modules: Packages | Node.js v19.3.0 Documentation
mjs extension. Files with a .js extension when the nearest parent package.json file contains a top-level "type" ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If your project does not have a package
type
field of"module"
, and your ESM is in.mjs
files because.js
is in CJS mode, and if you need to use a pure ESM dev dependency within the project ESLint config file, you are screwed. Theeslint.config.js
file is in CJS mode, meaning you can’trequire
the ESM dev dependency. ESLint must add support foreslint.config.mjs
files.If in the future ESLint decides to support only one config file name and format that any project could use, it would be
eslint.config.mjs
because that will always work as ESM no matter what the packagetype
field is configured to, and the ESM format is capable of importing from both ESM as well as CJS dev dependencies.Whoops! that does it, thanks. That’s a decent workaround.