Skip to content

Conversation

aladdin-add
Copy link
Member

@aladdin-add aladdin-add commented Oct 6, 2025

Prerequisites checklist

What is the purpose of this pull request?

when running npx eslint ., it output the errors:

Oops! Something went wrong! :(

ESLint: 9.37.0

TypeError: Plugin config "mixed-esm-and-cjs" not found in plugin "n".
    at findPluginConfig (/tmp/tmp.6CcU4BUgW5/node_modules/@eslint/config-helpers/dist/cjs/index.cjs:287:8)
    at /tmp/tmp.6CcU4BUgW5/node_modules/@eslint/config-helpers/dist/cjs/index.cjs:423:25
    at Array.map (<anonymous>)
    at processExtends (/tmp/tmp.6CcU4BUgW5/node_modules/@eslint/config-helpers/dist/cjs/index.cjs:421:36)
    at /tmp/tmp.6CcU4BUgW5/node_modules/@eslint/config-helpers/dist/cjs/index.cjs:497:38
    at Array.flatMap (<anonymous>)
    at processConfigList (/tmp/tmp.6CcU4BUgW5/node_modules/@eslint/config-helpers/dist/cjs/index.cjs:497:20)
    at defineConfig (/tmp/tmp.6CcU4BUgW5/node_modules/@eslint/config-helpers/dist/cjs/index.cjs:533:9)
    at file:///tmp/tmp.6CcU4BUgW5/eslint.config.mjs?mtime=1759647699530:6:16
    at ModuleJob.run (node:internal/modules/esm/module_job:345:25)
Oops! Something went wrong! :(

ESLint: 9.37.0


A config object has a "plugins" key defined as an array of strings. It looks something like this:

    {
        "plugins": ["eslint-plugin"]
    }

Flat config requires "plugins" to be an object, like this:

    {
        plugins: {
            eslint-plugin: pluginObject
        }
    }

Please see the following page for information on how to convert your config object into the correct format:
https://eslint.org/docs/latest/use/configure/migration-guide#importing-plugins-and-custom-parsers

If you're using a shareable config that you cannot rewrite in flat config format, then use the compatibility utility:
https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config

fixes #227

What changes did you make? (Give an overview)

  • use the flat config directly, instead of guessing the config format.

Related Issues

Is there anything you'd like reviewers to focus on?

const config = {plugins: ["eslint-plugin"]};

this is wrongly seen as flat config; we might need to fix it in @eslint/config-helper.

@MikeMcC399
Copy link
Contributor

@aladdin-add

Using the changed config

import { defineConfig } from "eslint/config";
import pluginJs from "@eslint/js";
import pluginNode from "eslint-plugin-n";
import eslintPlugin from "eslint-plugin-eslint-plugin";

export default defineConfig([
    {
        name: "eslint/js",
        plugins: {
            js: pluginJs,
        },
        extends: ["js/recommended"],
    },
    {
        name: "eslint/node",
        plugins: {
            n: pluginNode,
        },
        extends: ["n/flat/mixed-esm-and-cjs"],
    },
    {
        name: "eslint/eslint-plugin",
        plugins: {
            "eslint-plugin": eslintPlugin,
        },
        extends: ["eslint-plugin/recommended"],
    }
]);

I'm getting a different error message from npm run lint:js:

$ npm run lint:js

> eslint-plugin-t@0.0.0 lint:js
> eslint .


Oops! Something went wrong! :(

ESLint: 9.37.0


A config object has a "plugins" key defined as an array of strings. It looks something like this:

    {
        "plugins": ["eslint-plugin"]
    }

Flat config requires "plugins" to be an object, like this:

    {
        plugins: {
            eslint-plugin: pluginObject
        }
    }

Please see the following page for information on how to convert your config object into the correct format:
https://eslint.org/docs/latest/use/configure/migration-guide#importing-plugins-and-custom-parsers

If you're using a shareable config that you cannot rewrite in flat config format, then use the compatibility utility:
https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config

Do you see this as well, or is it working for you?

@aladdin-add
Copy link
Member Author

Yes, I noticed that, too. I will investigate.

@aladdin-add aladdin-add marked this pull request as draft October 6, 2025 17:41
@aladdin-add
Copy link
Member Author

aladdin-add commented Oct 6, 2025

  1. upgrading eslint-plugin-eslint-pluginv7.
  2. use the prefixed config extends: ["eslint-plugin/flat/recommended"].

Both can solve the issue. 😂

@aladdin-add aladdin-add changed the title fix: Change ESLint config extension to 'n/flat/mixed-esm-and-cjs' fix: eslint config error when using defineConfig Oct 6, 2025
@MikeMcC399
Copy link
Contributor

@aladdin-add

Thanks for your actions! 👍🏻 This was much more complicated than I could understand and fix on my own!

@aladdin-add aladdin-add marked this pull request as ready for review October 6, 2025 18:19
@aladdin-add aladdin-add moved this from Needs Triage to Implementing in Triage Oct 6, 2025
fixes #227

1. The `mixed-esm-and-cjs` configuration does not exist the eslintrc version,
 and config-helper does not seem to handle this scenario well.
2. use `eslint-plugin/flat/recommended`, as `recommended`is eslintrc-style.
Copy link
Contributor

@MikeMcC399 MikeMcC399 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I successfully ran https://github.com/eslint/generator-eslint/blob/aladdin-add-patch-2/plugin/templates/_eslint.config.mjs locally with npm run lint:js, so that looks good to go!

Thank you very much!

Comment on lines -19 to +26
extends: ["n/mixed-esm-and-cjs"],
extends: ["n/flat/mixed-esm-and-cjs"],
},
{
name: "eslint/eslint-plugin",
plugins: {
"eslint-plugin": eslintPlugin,
},
extends: ["eslint-plugin/recommended"],
extends: ["eslint-plugin/flat/recommended"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change necessary if eslint/rewrite#288 is accepted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's necessary, that pr is only fixing the eslint-plugin-n issue.

Copy link
Member Author

@aladdin-add aladdin-add Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cause is defineConfig() simply check whether the property exists rather than determining its type to verify if it conforms to the eslintrc format:
https://github.com/eslint/rewrite/blob/4334e769be7cfe5b515d64058176571aab18ea5c/packages/config-helpers/src/define-config.js#L76-L84

const config = {plugins: ["eslint-plugin"]};

the config will be treated as flat config, while actually it's eslintrc format.

Copy link
Member

@mdjermanovic mdjermanovic Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, both config formats have a plugins property, but of different type. Maybe that could be another improvement in addition to eslint/rewrite#288. Either way, since there are multiple issues, I agree with this fix (even if it's temporary) in generator-eslint.

Copy link
Member

@lumirlumir lumirlumir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Would like @mdjermanovic to verify before merging.

@lumirlumir lumirlumir moved this from Implementing to Second Review Needed in Triage Oct 7, 2025
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@mdjermanovic mdjermanovic merged commit d13113e into main Oct 7, 2025
11 checks passed
@mdjermanovic mdjermanovic deleted the aladdin-add-patch-2 branch October 7, 2025 10:52
@github-project-automation github-project-automation bot moved this from Second Review Needed to Complete in Triage Oct 7, 2025
@github-actions github-actions bot mentioned this pull request Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

Lint failure: TypeError: Plugin config "mixed-esm-and-cjs" not found in plugin "n".

4 participants