You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

加载@typescript-eslint/await-thenable规则报错,配置tsconfig仍未解决

问题排查与解决方案

核心问题

你子包的ESLint配置使用了@babel/eslint-parser,但@typescript-eslint/await-thenable这类规则依赖TypeScript类型信息,必须搭配@typescript-eslint/parser才能正常工作。@babel/eslint-parser无法提供TypeScript类型检查所需的parserServices,这是报错的根本原因。

修复步骤

  • 替换ESLint解析器
    在子包的eslintrc.cjs中,把parser从@babel/eslint-parser替换为@typescript-eslint/parser,确保父包或子包已安装该依赖。

  • 修正parserOptions配置
    保留project字段,新增tsconfigRootDir指定子包根目录,避免Yarn Workspace结构下的路径解析错误;同时移除requireConfigFile: false,因为@typescript-eslint/parser需要依赖tsconfig文件获取类型信息:

    parserOptions: {
      ecmaVersion: 11,
      sourceType: 'module',
      ecmaFeatures: {
        jsx: true
      },
      project: './tsconfig.eslint.json',
      tsconfigRootDir: __dirname, // 指定当前子包目录
    },
    
  • 检查tsconfig.eslint.json配置
    确保子包的tsconfig.eslint.json包含所有需要lint的文件,示例:

    {
      "extends": "./tsconfig.json",
      "include": [
        "src/**/*",
        "*.js",
        "*.cjs"
      ]
    }
    
  • 处理父包继承的规则
    确保父包的ESLint配置中,@typescript-eslint相关规则是通过plugin:@typescript-eslint/recommended-type-checked这类包含类型检查的扩展引入,而非单独开启await-thenable规则。

调整后的完整eslintrc.cjs示例

module.exports = {
  plugins: ['prettier', '@typescript-eslint'],
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended-type-checked',
    'prettier'
  ],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaVersion: 11,
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true
    },
    project: './tsconfig.eslint.json',
    tsconfigRootDir: __dirname,
  },
  env: {
    es6: true,
    browser: true,
    node: true,
    jest: true
  },
  rules: {
    'no-debugger': 2,
    'no-alert': 2,
    'no-await-in-loop': 0,
    'no-prototype-builtins': 0,
    'no-return-assign': ['error', 'except-parens'],
    'no-restricted-syntax': [
      2,
      'ForInStatement',
      'LabeledStatement',
      'WithStatement'
    ],
    '@typescript-eslint/no-unused-vars': [
      0,
      {
        ignoreSiblings: true,
        argsIgnorePattern: 'React|res|next|^_'
      }
    ],
    'prefer-const': [
      'error',
      {
        destructuring: 'all'
      }
    ],
    'no-unused-expressions': [
      2,
      {
        allowTaggedTemplates: true
      }
    ],
    'no-console': 1,
    'comma-dangle': 2,
    'jsx-quotes': [2, 'prefer-double'],
    'linebreak-style': ['error', 'unix'],
    quotes: [
      2,
      'single',
      {
        avoidEscape: true,
        allowTemplateLiterals: true
      }
    ],
    'prettier/prettier': [
      'error',
      {
        trailingComma: 'none',
        singleQuote: true,
        printWidth: 80
      }
    ]
  }
};

内容的提问来源于stack exchange,提问作者David Choi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 15:50:29