Monorepo 中的打字稿 eslint tsconfig 解析错误

den*_*dog 5 typescript eslint visual-studio-code monorepo typescript-eslint

我有以下项目结构:

/root
  /serviceA 
  /serviceB
  /serviceC 
  /serviceD 
Run Code Online (Sandbox Code Playgroud)

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

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

Parsing error: Cannot read file '/users/{me}/dev/{root}/tsconfig.json'.
Run Code Online (Sandbox Code Playgroud)

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

小智 8

使用以下命令编辑您的.eslintrc文件:


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

Run Code Online (Sandbox Code Playgroud)

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

  • 我已经有了这个,但它不起作用。 (3认同)

Dav*_*haw 1

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

\n
parserOptions : {\n  project: \'./tsconfig.json\',\n},\n
Run Code Online (Sandbox Code Playgroud)\n

这里\xe2\x80\x99s是一个例子,它只是为ts文件设置的

\n

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

\n

  • 抱歉这么长时间的延迟,但我已经在每个 ES lint 配置文件中都有这个了。 (3认同)