【问题标题】:Typescript eslint tsconfig resolution error in monorepoMonorepo中的Typescript eslint tsconfig解析错误
【发布时间】:2020-11-30 22:31:50
【问题描述】:

我的项目结构如下:

/root
  /serviceA 
  /serviceB
  /serviceC 
  /serviceD 

并不是所有的服务都是基于打字稿/节点的,所以我想避免将 tsconfig 添加到根目录中。每个服务都设置为一个完整的单元,具有自己的 eslint、ts 和自己的配置安装。

我打开 VScode 的任何ts 服务都显示以下错误:

Parsing error: Cannot read file '/users/{me}/dev/{root}/tsconfig.json'.

这是正确的,因为没有这样的文件,那么如何强制 vscode & eslint 使用单个服务配置文件?

【问题讨论】:

    标签: typescript visual-studio-code eslint monorepo typescript-eslint


    【解决方案1】:

    编辑您的.eslintrc 文件:

    
    module.exports = {
      parserOptions: {
        project: './tsconfig.json',
        tsconfigRootDir: __dirname,
      },
    };
    
    

    来源:https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-488538828

    【讨论】:

    • 我已经有了这个,但它不工作。
    【解决方案2】:

    .eslintrc 中,您可以将路径设置为tsconfig.json

    parserOptions : {
      project: './tsconfig.json',
    },
    

    这是一个只为 ts 文件设置的示例

    https://github.com/davidjbradshaw/eslint-config-auto/blob/master/rules/%40typescript-eslint/parser.js

    【讨论】:

    • 抱歉耽搁了很长时间,但我已经在每个 ES lint 配置文件中都有这个。
    猜你喜欢
    • 2021-11-01
    • 2020-05-06
    • 2019-12-06
    • 2021-06-05
    • 2020-11-10
    • 2021-12-24
    • 2022-11-19
    • 2017-10-11
    • 2019-12-25
    相关资源
    最近更新 更多