ESLint 找不到要扩展的配置...

症状

¥Symptoms

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

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

ESLint couldn't find the config "${configName}" to extend from. Please check that the name of the config is correct.

The config "${configName}" was referenced from the config file in "${importerName}".

原因

¥Cause

ESLint 配置文件通过 extends 数组中的包名称指定可共享配置。该包名称被传递到 Node.js require(),后者在本地 node_modules/ 目录下查找该包。例如,以下 ESLint 配置将首先尝试加载位于 node_modules/eslint-config-yours 的模块:

¥ESLint configuration files specify shareable configs by their package name in the extends array. That package name is passed to the Node.js require(), which looks up the package under local node_modules/ directories. For example, the following ESLint config will first try to load a module located at node_modules/eslint-config-yours:

module.exports = {
    extends: ["eslint-config-yours"],
};

当你尝试从配置扩展并且在任何搜索的 node_modules/ 中找不到该配置的包时,会输出该错误。

¥The error is output when you attempt to extend from a configuration and the package for that configuration is not found in any searched node_modules/.

发生这种情况的常见原因包括:

¥Common reasons for this occurring include:

  • 未运行 npm install 或等效的包管理器命令

    ¥Not running npm install or the equivalent package manager command

  • 错误输入包和/或配置的区分大小写的名称

    ¥Mistyping the case-sensitive name of the package and/or configuration

配置名称变化

¥Config Name Variations

请注意,ESLint 支持多种配置名称格式:

¥Note that ESLint supports several config name formats:

  • 为了简洁起见,可以省略 eslint-config- 配置名称前缀,例如 extends: ["yours"]

    ¥The eslint-config- config name prefix may be omitted for brevity, e.g. extends: ["yours"]

    • @ npm 范围包eslint-config- 前缀放在组织范围之后,例如 extends: ["@org/yours"]@org/eslint-config-yours 加载

      ¥@ npm scoped packages put the eslint-config- prefix after the org scope, e.g. extends: ["@org/yours"] to load from @org/eslint-config-yours

  • plugin: 前缀表示配置是从共享插件加载的,例如 extends: [plugin:yours/recommended]eslint-plugin-yours 加载

    ¥A plugin: prefix indicates a config is loaded from a shared plugin, e.g. extends: [plugin:yours/recommended] to load from eslint-plugin-yours

解析

¥Resolution

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

¥Common resolutions for this issue include:

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

    ¥Upgrading all versions of all packages to their latest version

  • 将配置添加为 package.json 中的 devDependency

    ¥Adding the config as a devDependency in your package.json

  • 运行 npm install 或等效的包管理器命令

    ¥Running npm install or the equivalent package manager command

  • 检查配置文件中的名称是否与配置包的名称匹配

    ¥Checking that the name in your config file matches the name of the config package

资源

¥Resources

有关更多信息,请参阅:

¥For more information, see:

ESLint 中文网
粤ICP备13048890号