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 installor 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 theeslint-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 fromeslint-plugin-yours
解析
¥Resolution
此问题的常见解决方案包括:
¥Common resolutions for this issue include:
-
将所有软件包的所有版本升级到最新版本。
¥Upgrading all versions of all packages to their latest version.
-
将配置作为
devDependency添加到你的package.json中。¥Adding the config as a
devDependencyin yourpackage.json. -
运行
npm install或等效的包管理器命令。¥Running
npm installor 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 配置文件 有关旧版 ESLint 配置格式的文档
¥Legacy ESLint configuration files for documentation on the legacy ESLint configuration format
-
旧版 ESLint 配置文件 > 使用可共享的配置包 有关使用可共享配置的文档
¥Legacy ESLint configuration files > Using a shareable configuration package for documentation on using shareable configurations
-
-
共享配置 有关如何定义独立共享配置的文档
¥Share Configurations for documentation on how to define standalone shared configs
-
创建插件 > 插件中的配置 有关如何在插件中定义共享配置的文档
¥Create Plugins > Configs in Plugins for documentation on how to define shared configs in plugins