Skip to content

eslint-plugin-import plugin error with workspaces #21

@davemarco

Description

@davemarco

In PR#1119, there is an issue when using workspaces with the eslint-plugin-import plugin.

Running npm run lint:check produces the following cryptic error:

ConfigError: Config "import/typescript": Key "plugins": Cannot redefine plugin "import".

After some investigation, the root cause is not entirely clear, but it appears related to the fact that node_modules are in a different location when using workspaces.

After testing, modifying CommonConfig.mjs to use importPlugin.flatConfigs.recommended appears to resolve the issue. This also aligns more closely with what the plugin recommends in its documentation.

For example, instead of:

import ImportPlugin from "eslint-plugin-import";

export default {
  plugins: {
    import: ImportPlugin,
  },
  rules: {
    // ...
  },
};

You can do:

import importPlugin from "eslint-plugin-import";

export default [
  importPlugin.flatConfigs.recommended,
  {
    rules: {
      // your additional rules
    },
  },
];

It's still unclear exactly why this works, but I did notice that the registered plugin name changes from:

import

to:

import:eslint-plugin-import@2.31.0.0/

when running npx eslint --print-config <config-path>.

Lastly, this fix requires converting CommonConfig into a CommonConfigArray, which I think is fine — but it will also require updates in the log viewer.

@junhaoliao, are okay with this change? If so i will make a PR to unblock PR#1119

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions