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

Eslint does not support common/module suffixes for Flat Config #22576

Closed
1 of 4 tasks
JacobLey opened this issue Mar 29, 2024 · 19 comments
Closed
1 of 4 tasks

Eslint does not support common/module suffixes for Flat Config #22576

JacobLey opened this issue Mar 29, 2024 · 19 comments
Assignees
Labels
outdated scope: linter Issues related to Eslint support in Nx type: bug

Comments

@JacobLey
Copy link
Contributor

Current Behavior

Eslint's new Flat Config supports 3 names:

  • eslint.config.js (inherits type from package.json, implied to be ESM otherwise)
  • eslint.config.cjs (explicitly commonjs)
  • eslint.config.mjs (explicitly ESM)

Supported suffixes comes from Eslint's documentation directly: This is quoted from Eslint's documentation itself: https://eslint.org/docs/latest/use/configure/configuration-files-new#configuration-file

The ESLint configuration file may be named any of the following:

However Nx's eslint does not recognize anything other than eslint.config.js.

This means it is not possible to explictly use CommonJS or ESM, especially if the desired format differs from what is in package.json

Expected Behavior

Nx's eslint respects all 3 file extensions for Flat Config

GitHub Repo

No response

Steps to Reproduce

Nx Report

Node   : 20.11.1
OS     : linux-arm64
npm    : 10.2.4

nx (global)  : 18.1.3
nx           : 18.1.3
@nrwl/tao    : 18.1.3

Failure Logs

When using the new Flat Config with ESLint, all configs must be named eslint.config.js and .eslintrc files may not be used. See https://eslint.org/docs/latest/use/configure/configuration-files-new

Package Manager Version

pnpm 8.15.4

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

Eslint executor versin: "@nx/eslint": "18.1.3"

This issue is admittedly light on reproducability, because I can just point directly in the code where these issues are occuring.

The following places explicitly hard code the eslint.config.js filename, and do not account for other extensions:

@FrozenPandaz FrozenPandaz added the scope: linter Issues related to Eslint support in Nx label Apr 2, 2024
@bneigher
Copy link

yea this is preventing me from my eslint 9 migration :/

@blordpluto
Copy link

Hi 👋 Can the team please offer some sort of expected timetable for this to be resolved? Flat config is the default in ESLint 9, which has been out for over a month now. Flat config itself has been available since 2022. For something very basic like this, we really would appreciate a bit more transparency about any scheduled fix. Thanks!

@fahslaj fahslaj assigned JamesHenry and unassigned JamesHenry and fahslaj May 14, 2024
@jotwea
Copy link

jotwea commented Jun 7, 2024

The solution for this issue might be here - there is already a TODO:
https://github.com/nrwl/nx/blob/master/packages/eslint/src/utils/config-file.ts#L4

export const ESLINT_FLAT_CONFIG_FILENAMES = ['eslint.config.js', 'eslint.config.mjs', 'eslint.config.cjs'];

@ak274
Copy link

ak274 commented Jun 26, 2024

Is there any plan to support flat config by default while creating new workspaces?
Because flat config is now default and recommended in ESLint Docs.

https://eslint.org/blog/2024/04/eslint-v9.0.0-released/#flat-config-is-now-the-default-and-has-some-changes

@robertIsaac
Copy link
Contributor

robertIsaac commented Jun 26, 2024

@ak274 I have already requested it #26338, so far no news

@robertIsaac
Copy link
Contributor

hi @benpsnyder
I see you have added support for .cjs but not .mjs and added TODO for it
when do we expect the .mjs to be done?

@benpsnyder
Copy link
Contributor

hi @benpsnyder

I see you have added support for .cjs but not .mjs and added TODO for it

when do we expect the .mjs to be done?

Adding support for .cjs was easy but I don't plan to work on .mjs at this time which will be harder to implement. I just solved the quick and easy task for now.

@robertIsaac
Copy link
Contributor

Can you explain what is hard about it
I can try to work on it on the weekend

@alfaproject
Copy link
Contributor

I just stumbled upon this as well, got a bit surprised when .mjs didn't work ):

@kuda1992
Copy link

When is this going to be fixed? Do you have a timeline? I am not able to use eslint.config.mjs

@codinronan
Copy link

For anyone who wants to use eslint.config.mjs you can do so now, you just end up forced to manually specify the lint task in your project.json files (since the config file is not picked up by the plugin, so the lint task is not automatically generated).

In my case, since we just use the simplest eslint . command it isn't a problem, but if you have a more complicated setup I guess it could be an issue.

Incidentally I do also have type: module in my package.json files so this may be why this works, I haven't tried changing it to commonjs since our build stack requires module anyway.

dr460nf1r3 added a commit to garuda-linux/startpage-v2 that referenced this issue Oct 20, 2024
@Stanzilla
Copy link
Contributor

@JamesHenry Would this be just adding the file name to https://github.com/nrwl/nx/blob/master/packages/eslint/src/utils/flat-config.ts#L5 here is there more? Willing to contribute if it is easy.

@ferenc-a
Copy link

typescript-eslint seems to have a workaround for now: https://github.com/typescript-eslint/typescript-eslint/blob/v8.18.1/eslint.config.js

@jaysoo
Copy link
Member

jaysoo commented Jan 6, 2025

It's not just adding to the array, since our AST utils will fail to update ESM right now, and you will run into errors.

We are adding support this month.

@ndcunningham
Copy link
Contributor

This should be supported now: #29613

@ferenc-a
Copy link

What version will this land in?

@finalight
Copy link

is it 20.3.2?

@ferenc-a
Copy link

ferenc-a commented Feb 3, 2025

Apparently in 20.4.0: https://github.com/nrwl/nx/releases/tag/20.4.0

Copy link

github-actions bot commented Mar 6, 2025

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: linter Issues related to Eslint support in Nx type: bug
Projects
None yet
Development

No branches or pull requests