设置eslint时常见问题收录

打印 上一主题 下一主题

主题 999|帖子 999|积分 2997

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
1. ESLint couldn’t find the plugin “@typescript-eslint/eslint-plugin”.

  1. Oops! Something went wrong! :(
  2. ESLint: 7.32.0
  3. ESLint couldn't find the plugin "@typescript-eslint/eslint-plugin".
  4. (The package "@typescript-eslint/eslint-plugin" was not found when loaded as a Node module from the directory "/Users/tal/Documents/web/my-vue3-project".)
  5. It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:
  6.     npm install @typescript-eslint/eslint-plugin@latest --save-dev
  7. The plugin "@typescript-eslint/eslint-plugin" was referenced from the config file in "BaseConfig".
  8. If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.
复制代码
这个错误表明 ESLint 没有找到 @typescript-eslint/eslint-plugin 插件,通常是由于插件没有精确安装或安装位置不精确。
  1. npm install --save-dev @typescript-eslint/eslint-plugin
复制代码
2. npm ERR! ERESOLVE unable to resolve dependency tree

  1. npm ERR! code ERESOLVE
  2. npm ERR! ERESOLVE unable to resolve dependency tree
  3. npm ERR!
  4. npm ERR! While resolving: my-vue3-project@0.1.0
  5. npm ERR! Found: eslint@7.32.0
  6. npm ERR! node_modules/eslint
  7. npm ERR!   dev eslint@"^7.32.0" from the root project
  8. npm ERR!
  9. npm ERR! Could not resolve dependency:
  10. npm ERR! peer eslint@"^8.57.0 || ^9.0.0" from @typescript-eslint/parser@8.2.0
  11. npm ERR! node_modules/@typescript-eslint/parser
  12. npm ERR!   peer @typescript-eslint/parser@"^8.0.0 || ^8.0.0-alpha.0" from @typescript-eslint/eslint-plugin@8.2.0
  13. npm ERR!   node_modules/@typescript-eslint/eslint-plugin
  14. npm ERR!     dev @typescript-eslint/eslint-plugin@"*" from the root project
  15. npm ERR!
  16. npm ERR! Fix the upstream dependency conflict, or retry
  17. npm ERR! this command with --force or --legacy-peer-deps
  18. npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
  19. npm ERR!
  20. npm ERR!
  21. npm ERR! For a full report see:
复制代码
由于依靠冲突导致 npm 无法精确剖析依靠树。我们添加使用 --legacy-peer-deps 参数便可以解决这个问题
  1. npm install --save-dev @typescript-eslint/eslint-plugin
  2. --legacy-peer-deps
复制代码
3. TypeError: Failed to load plugin ‘@typescript-eslint’ declared in ‘.eslintrc.js’: Class extends value undefined is not a constructor or null

这个问题大概与依靠之间的不兼容有关,特别是由于 ESLint 版本和 @typescript-eslint 相关库之间的冲突。
解决方法:
  1. npm install --save-dev eslint@latest @typescript-eslint/eslint-plugin@latest @typescript-eslint/parser@latest --legacy-peer-deps
复制代码
4. Invalid option ‘–ext’ - perhaps you meant ‘-c’?

  1. npm run lint
  2. > my-vue3-project@0.1.0 lint
  3. > eslint --ext .js,.mjs,.cjs,.ts,.vue
  4. Invalid option '--ext' - perhaps you meant '-c'?
  5. You're using eslint.config.js, some command line flags are no longer available. Please see https://eslint.org/docs/latest/use/command-line-interface for details.
复制代码
出现这个,就代表在使用新的 eslint.config.js 设置格式时,某些命令行选项(例如 --ext)已经被弃用或不再必要,但是我的文件却是是.eslintrc.js。
检查 ESLint 版本: 确保你的 ESLint 版本支持 --ext 选项。
  1. npx eslint -v
复制代码
ESLint 8.x 版本仍旧支持 .eslintrc.js 和 --ext 参数。
重新执行install:
  1. npm install eslint@8.39.0 eslint-plugin-vue@9.11.0 --save-dev
复制代码
此时,假如你想继续使用 .eslintrc.js,那么以下命令是有用的:
  1. npx eslint .
  2. --ext .js,.mjs,.cjs,.ts,.vue
复制代码
5. eslint 版本不一致

假如你是新项目,那么按照上面的设置来,很少出现问题。但是假如你是在老项目上重新加eslint,我的发起是非必要不加。
但是假如必要加的话,发起你先完成“执行Eslint检查”,然后触发npm run lint,看下有哪些文件、代码出现问题。而且你大概刚出现以下问题:
  1. [plugin:vite-plugin-eslint] Failed to load plugin '@typescript-eslint' declared in '.eslintrc.js': Class extends value undefined is not a constructor or null
复制代码
有时间,@typescript-eslint 插件的版本较旧大概与较新的 ESLint 版本不兼容。以下是解决此问题的一些步骤:
1、更新 @typescript-eslint 插件。实验将 @typescript-eslint 插件更新到最新版本。使用以下命令更新:
  1. npm install @typescript-eslint/eslint-plugin@latest @typescript-eslint/parser@latest --save-dev
复制代码

  • 确保 vite-plugin-eslint 插件是最新的。
  1. npm install vite-plugin-eslint@latest --save-dev
复制代码
3、清除缓存并重新安装依靠。删除 node_modules 和 package-lock.json,然后重新安装所有依靠:
  1. rm -rf node_modules package-lock.json
  2. npm install
复制代码

  • 手动运行 ESLint 检查。确保 ESLint 本身可以正常运行。在项目目录中,使用以下命令运行 ESLint:
  1. npx eslint src --ext .js,.ts,.vue
复制代码
假如以上步骤没有解决问题,可以参考 ESLint、@typescript-eslint 和 vite-plugin-eslint 的官方文档和 GitHub 问题跟踪器,看看是否有类似问题的解决方案。
6. Invalid option ‘–ext’ - perhaps you meant ‘-c’?You’re using eslint.config.js, some command line flags are no longer available.

  1. > eslint .
  2. --ext .js,.mjs,.cjs,.ts,.vue
  3. Invalid option '--ext' - perhaps you meant '-c'?
  4. You're using eslint.config.js, some command line flags are no longer available. Please see https://eslint.org/docs/latest/use/command-line-interface for details.
复制代码
在使用 eslint.config.mjs 设置文件时,ESLint 的命令行选项有所不同。--ext 选项在使用新的 eslint.config.* 文件时不再可用,由于文件扩展名可以直接在设置文件中指定。
已经在 eslint.config.mjs 文件中指定了匹配模式为 **/*.{js,mjs,cjs,ts,vue},这会告诉 ESLint 自动处置惩罚这些扩展名的文件,因此无需在命令行中指定 --ext。
使用 eslint 命令直接运行:
直接使用一下命令:
  1. eslint .
复制代码
假如您必要进一步自界说检查的目录或文件,可以在命令行中指定目录或文件路径,而无需使用 --ext 选项。例如:
  1. eslint src/
复制代码
7. ConfigError: Config (unnamed): Key “rules”: Key “constructor-super”: structuredClone is not defined

  1. > eslint .
  2. Oops! Something went wrong! :(ESLint: 9.8.0ConfigError: Config (unnamed): Key "rules": Key "constructor-super": structuredClone is not defined
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

万有斥力

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表