首页 > 解决方案 > 为什么 tsc 忽略 tsconfig.json 中的 include 和 exclude?

问题描述

我有tsconfig.json

{
  "compilerOptions": {
    "target": "ES6",
    "lib": [
      "DOM",
      "ES6"
    ]
  },
  "include": [
    "src/server/**/*"
  ],
  "exclude": [
    "node_modules",
    "dist",
    "public"
  ]
}

当我运行tsc --project tsconfig.json它时,它完全忽略了include和配置并且编译exclude失败。node_modules

它成功的唯一方法是tsc src/server/**/*.ts,但后来它没有使用配置。

我验证了编译器会处理配置,因为当我添加"watch": true到时"compilerOptions",它会等待更改。

我查看了文档,但没有得到它。看起来我把它放在了 json 文件中的正确位置。

有谁知道,如何解决它?


macOS Big Sur 上的编译器版本:

% tsc -v
Version 4.0.5

标签: typescripttsctsconfig

解决方案


正如问题下方的评论中所写,我必须添加"skipLibCheck": true,所以最终的 json 看起来像:

{
  "compilerOptions": {
    "target": "ES6",
    "lib": [
      "DOM",
      "ES6"
    ],
    "skipLibCheck": true
  },
  "include": [
    "src/server/**/*"
  ],
  "exclude": [
    "node_modules",
    "dist",
    "public"
  ]
}

然后编译成功:

% tsc -p tsconfig.json 
% echo $?
0

推荐阅读