版本

ESLint 找不到外掛程式 …

症狀

當使用舊版 ESLint 設定系統時,您可能會在安裝相依性後執行 ESLint 時看到此錯誤

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}".

原因

舊版 ESLint 設定檔會依其套件名稱指定可共用設定。該套件名稱會傳遞至 Node.js 的 require(),後者會在本地 node_modules/ 目錄下尋找該套件。例如,以下 ESLint 設定會先嘗試載入位於 node_modules/eslint-plugin-yours 的模組

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

如果找不到任何搜尋到的 node_modules/ 中的套件,ESLint 將會印出上述錯誤。

發生此情況的常見原因包括

  • 未執行 npm install 或對等的套件管理員命令
  • 外掛程式的區分大小寫名稱輸入錯誤

外掛程式名稱變體

請注意,為了簡潔起見,可以省略 eslint-plugin- 外掛程式名稱前綴,例如 extends: ["yours"]

@ npm 作用域套件eslint-plugin- 前綴放在組織作用域之後,例如 extends: ["@org/yours"],以便從 @org/eslint-plugin-yours 載入。

解決方法

此問題的常見解決方案包括

  • 將所有套件的所有版本升級到最新版本
  • 在您的 package.json 中將外掛程式新增為 devDependency
  • 執行 npm install 或對等的套件管理員命令
  • 檢查您的設定檔中的名稱是否與外掛程式套件的名稱相符

資源

如需更多資訊,請參閱

變更語言