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 plugin "${pluginName}".

(The package "${pluginName}" was not found when loaded as a Node module from the directory "${resolvePluginsRelativeTo}".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

    npm install ${pluginName}@latest --save-dev

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

原因

¥Cause

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

¥Legacy ESLint configuration files specify shareable configs by their package name. 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-plugin-yours:

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

如果在任何搜索的 node_modules/ 中都没有找到该包,ESLint 将打印上述错误。

¥If the package is not found in any searched node_modules/, ESLint will print the aforementioned error.

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

¥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 plugin

插件名称变体

¥Plugin Name Variations

请注意,为了简洁起见,可以省略 eslint-plugin- 插件名称前缀,例如 extends: ["yours"]

¥Note that the eslint-plugin- plugin name prefix may be omitted for brevity, e.g. extends: ["yours"].

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

¥@ npm scoped packages put the eslint-plugin- prefix after the org scope, e.g. extends: ["@org/yours"] to load from @org/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 plugin 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 plugin package

资源

¥Resources

有关更多信息,请参阅:

¥For more information, see:

ESLint 中文网
粤ICP备13048890号