【问题标题】:Why does tsc ignore include and exclude in tsconfig.json?为什么 tsc 忽略 tsconfig.json 中的 include 和 exclude?
【发布时间】:2025-12-04 18:40:01
【问题描述】:

我有tsconfig.json:

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

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

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

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

我查看了documentation,但没听懂。看起来我把它放在了 json 文件中的正确位置。

有人知道如何解决吗?


macOS Big Sur 上的编译器版本:

% tsc -v
Version 4.0.5

【问题讨论】:

  • 尝试将 "skipLibCheck":true 添加到您的 tsconfig 中

标签: typescript tsc tsconfig


【解决方案1】:

正如问题下方的评论中所写,我必须添加"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

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,我解决了,但升级了打字稿:

    npm install -g typescript 
    

    【讨论】: