【已解决】在 Vite 项目中使用 eslint-config-ali 时遇到的解析错误

重现错误

  1. 搭建 Vite 项目
pnpm create vite my-vue-app --template vue
  1. 安装
pnpm i -D eslint-config-ali @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-import eslint-import-resolver-typescript vue-eslint-parser eslint-plugin-vue
  1. 配置 .eslintrc
{
  "extends": ["eslint-config-ali/typescript/vue"]
}

错误信息

vite.config.ts 首行开始处位置:

Parsing error: ESLint was configured to run on <tsconfigRootDir>/vite.config.ts using parserOptions.project: <tsconfigRootDir>/tsconfig.json

However, that TSConfig does not include this file. Either:

  • Change ESLint’s list of included files to not include this file

  • Change that TSConfig to include this file

  • Create a new TSConfig that includes this file and include it in your parserOptions.project

See the typescript-eslint docs for more info: https://typescript-eslint.io/linting/troubleshooting#i-get-errors-telling-me-eslint-was-configured-to-run–however-that-tsconfig-does-not–none-of-those-tsconfigs-include-this-file

错误原因

ESLint 识别包含在 include 属性中的内容,默认是从 tsconfig.json 中读取的,而 vite.config.ts 包含在 tsconfig.node.jsoninclude 属性中,通过 references 属性引用到 tsconfig.json 中,造成了 ESLint 识别不到该文件。

解决错误

修改 .eslintrcparserOptions.project 配置,增加 tsconfig.node.json,如下:

{
  "extends": ["eslint-config-ali/typescript/vue"],
  "parserOptions": {
    "project": ["tsconfig.json", "tsconfig.node.json"]
  }
}

🎉 搞定!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值