ESLint 无法确定插件...唯一

症状

¥Symptoms

使用 旧版 ESLint 配置系统 时,安装依赖后运行 ESLint 时可能会看到此错误:

¥When using the legacy ESLint config system, you may see this error running ESLint after installing dependencies:

ESLint couldn't determine the plugin "${pluginId}" uniquely.

- ${filePath} (loaded in "${importerName}")
- ${filePath} (loaded in "${importerName}")
...

Please remove the "plugins" setting from either config or remove either plugin installation.

原因

¥Cause

ESLint 配置文件允许加载可能包含其他插件的插件。插件包可能会被指定为你的包和一个或多个 ESLint 插件的依赖。旧版 ESLint 配置文件可能使用 extends 来包含其他配置。这些配置可能依赖于插件来提供配置中的某些功能。

¥ESLint configuration files allow loading in plugins that may include other plugins. A plugin package might be specified as a dependency of both your package and one or more ESLint plugins. Legacy ESLint configuration files may use extends to include other configurations. Those configurations may depend on plugins to provide certain functionality in the configuration.

例如,如果你的配置依赖于 eslint-plugin-a@2eslint-plugin-b@3,并且你扩展了依赖于 eslint-plugin-a@1eslint-config-b,则 eslint-plugin-a 包可能在磁盘上有两个不同的版本:

¥For example, if your config depends on eslint-plugin-a@2 and eslint-plugin-b@3, and you extend eslint-config-b that depends on eslint-plugin-a@1, then the eslint-plugin-a package might have two different versions on disk:

  • node_modules/eslint-plugin-a

  • node_modules/eslint-plugin-b/node_modules/eslint-plugin-a

如果旧版 ESLint 配置系统发现这两个插件存在于多个不同版本的地方,它将不知道该使用哪一个。

¥If the legacy ESLint configuration system sees that both plugins exists in multiple places with different versions, it won’t know which one to use.

请注意,此问题仅存在于旧版 eslintrc 配置中。新的 “flat” 配置系统 让你自己 import 依赖,从而无需 ESLint 尝试唯一确定其版本。

¥Note that this issue is only present in the legacy eslintrc configurations. The new “flat” config system has you import the dependencies yourself, removing the need for ESLint to attempt to determine their version uniquely.

解析

¥Resolution

此问题的常见解决方案包括:

¥Common resolutions for this issue include:

  • 将所有软件包的所有版本升级到最新版本

    ¥Upgrading all versions of all packages to their latest version

  • 如果版本范围兼容,则运行 npm dedupe 或等效的包管理器命令来删除重复包

    ¥Running npm dedupe or the equivalent package manager command to deduplicate packages, if their version ranges are compatible

  • 使用 overrides 或等效的包管理器 package.json 字段,强制使用特定版本的插件包

    ¥Using overrides or the equivalent package manager package.json field, to force a specific version of a plugin package

    • 请注意,如果插件包在版本之间发生重大更改,这可能会导致 linting 错误

      ¥Note that this may cause bugs in linting if the plugin package had breaking changes between versions

资源

¥Resources

有关更多信息,请参阅:

¥For more information, see:

ESLint 中文网
粤ICP备13048890号