Failed to load plugin jsdoc: Cannot find module ‘eslint-plugin-jsdoc‘

蔚和安
2023-12-01

在 egg 项目中,初次安装 npm 包的时候,报错如下:

Oops! Something went wrong! :(

ESLint: 5.16.0.
ESLint couldn't find the plugin "eslint-plugin-jsdoc". This can happen for a couple different reasons:

1. If ESLint is installed globally, then make sure eslint-plugin-jsdoc is also installed globally. A globally-installed ESLint cannot find a locally-installed plugin.

2. If ESLint is installed locally, then it's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

     npm i eslint-plugin-jsdoc@latest --save-dev

Path to ESLint package: /Users/***/node_modules/eslint

If you still can't figure out the problem, please stop by https://gitter.im/eslint/eslint to chat with the team.

ESlint 也自然是没有正常工作,并且当文件不符合 ESlint 规则时,在控制台日志报错如下:

Failed to load plugin jsdoc: Cannot find module 'eslint-plugin-jsdoc'....

原因:

npm v8.0 在安装项目依赖的时候,没有正确安装上项目依赖(eslint-config-egg)的依赖(eslint-plugin-jsdoc)

解决:

将 npm 升级到 v8.1.2 后,删除项目中的 node_modules 和 package-lock.json,然后重新安装

rm -rf node_modules
rm package-lock.json
npm i

补充:

如果你有同样的报错,可以通过全局搜索 eslint-plugin-jsdoc,配合 npm 命令定位依赖关系

➜  *** git:(master) ✗ npm ls eslint-plugin-jsdoc
***@1.0.0 /Users/***
└─┬ eslint-config-egg@7.5.1
  └── eslint-plugin-jsdoc@4.8.4

进而判定是要手动安装还是升级 npm 或者因为其他原因导致的。

 类似资料: