typescript - 為什麼 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,但那樣就沒有使用設定檔。
我已經驗證過,編譯器會處理配置,因為當我在 "compilerOptions" 中添加 "watch": true 時,它會等待變更。
我查看了文件說明,但我還是不明白。看起來我已經把它放在 JSON 檔案中的正確位置了。
有人知道該怎麼修理它嗎?
macOS Big Sur上的編譯器版本:
% tsc -v
Version 4.0.5
答案#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
我有相同的問題,我透過升級 TypeScript 解決了它:
npm install -g typescript
