在 tsconfig.json 配置中找不到任何输入

tsconfig.json 文件内容如下,这种情况下很可能就会出现错误

在配置文件 /path/to/program/tsconfig.json 中找不到任何输入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"compilerOptions": {
"baseUrl": ".",
"outDir": "dist",
"module": "esnext",
"target": "es2016",
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true,
"paths": {
"*": [
"node_modules/*",
"src/types/*"
]
},
"typeRoots": ["typings", "node_modules/@types"]
},
"exclude": [
"node_modules"
]
}

只需要添加一个 include 数组指定包含的目录即可,或者也可以添加一个 files 数组指定包含的文件列表。

比如:

1
2
3
4
5
6
7
8
9
10
11
12
{
"include": [
"src/**/*"
],
// Or/And files
"files": [
"src/app.ts"
],
"exclude": [
"node_modules"
]
}

但是不能设置为一个空数组,"include": [] 这样还是会找不到任何输入的,同样的,如果设置的路径不对,依然有这个错误。

另有一种情况:项目内没有 typescript 文件,此时即使有 include 属性也依然会有错误提示。这时候要么删除 tsconfig.json 文件,毕竟在项目没有 typescript 文件时,有 tsconfig.json 文件本身就有些奇怪;但如果因为各种各样的原因,不能/不想删除它的话,也可以在项目中随便写一个 ts 文件,包含在 includefiles 属性中。

附带一提,tslint.json 文件可以用 tslint.js 替代,使用 module.exports 导出。
这样可以根据环境配置来设置不同的 lint 规则。