tsconfig.json: Build:在配置文件中找不到任何输入

418

我有一个ASP.NET核心项目,在尝试构建它时遇到了这个错误:

error TS18003: Build:No inputs were found in config file 'Z:/Projects/client/ZV/src/ZV/Scripts/tsconfig.json'. Specified 'include' paths were '["**/*"]' and 'exclude' paths were '["../wwwroot/app","node_modules/*"]'.
1>         The command exited with code 1.
1>       Done executing task "VsTsc" -- FAILED.

这是我的tsconfig.json文件:

{
  "compileOnSave": true,
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [ "es5", "dom" ],
    "module": "commonjs",
    "moduleResolution": "node",
    "noEmitOnError": true,
    "noImplicitAny": false,
    "outDir": "../wwwroot/app/",
    "removeComments": false,
    "sourceMap": true,
    "target": "es6"
  },
  "exclude": [
    "../wwwroot/app",
    "node_modules/*"
  ]
}

这是一个bug还是我做错了什么?我最近将Visual Studio 2015升级到了更新3。有人之前遇到过这种情况吗?


22
这是预期行为。您需要有要编译的东西。 - Aluan Haddad
1
@AluanHaddad,你说得好像这是事实一样。你能否提供证据来支持你的说法? - Serj Sagan
4
https://github.com/Microsoft/TypeScript/issues/12762 - Aluan Haddad
你的源代码应该是在tsconfig中“include”指向的位置。 - Mohammad Kermani
默认的 tsconfig.json 没有 "include" 和 "exclude" 属性,所以我不得不添加两者。由于某种原因,似乎两者都是必需的。 - nth-chile
我遇到了这个问题,是因为我拥有的TypeScript文件是空的。 - Dhruv Anand
34个回答

8
我解决问题的方法是在配置文件中的每个包含路径前添加"./":
"include": ["./src/**/*.d.ts", "./src/**/*.js", "./src/**/*.svelte"]

8
"outDir"

应该与之不同

"rootDir"

示例

    "outDir": "./dist",
    "rootDir": "./src", 

7

要使用 tsc 命令,您需要具备根目录下的 index.tsxindex.ts 文件。


5
我在根目录(Visual Studio)中添加了以下内容。
{
  "compilerOptions": {
    "allowJs": true,
    "noEmit": true,
    "module": "system",
    "noImplicitAny": true,
    "removeComments": true,
    "preserveConstEnums": true,
    "sourceMap": true
  },
  "include": [
    "**/*"
  ],
  "exclude": [
    "assets",
    "node_modules",
    "bower_components",
    "jspm_packages"
  ],
  "typeAcquisition": {
    "enable": true
  }
}

3
一个空的 "exclude": [ "" ] 也可以奏效(用于覆盖默认值,即 ./)。 - spygi

4

好的,在2021年,使用一个<project>/src/index.ts文件时,以下方法适用于我:

如果VS Code报错显示“在配置文件中未找到输入...”,则将include更改为...

"include": ["./src/**/*.ts"]

在这篇《如何用TypeScript编写Node.js应用程序》 的评论中发现上述信息。


3
在“include”标签中添加.ts文件位置,然后编译就可以正常工作。例如:
"include": [
"wwwroot/**/*" ]

3
使用Visual Studio Code时,构建项目(即按下Ctrl + Shift + B)会将您的.ts文件移动到.vscode文件夹中(我不知道为什么会这样),然后生成TS18003错误。我的做法是将我的.ts文件从.vscode文件夹中移出,放回根文件夹并再次构建项目。成功地构建了该项目!

1
它将 .tsconfig 文件放置在 .vscode 文件夹中。如果您将其移出 .vscode 文件夹,则可能还需要编辑 .vscode/tasks.json 以指向新位置。 - duggulous

3

我的VSCode在tsconfig.json文件的开头给了我一个波浪线,而且出现了同样的错误,所以

  1. 我确保我在“include”路径中指定的文件夹中至少有一个.ts文件(包含路径中的其中一个文件夹为空也没有问题)
  2. 我只是简单地关闭了VSCode,然后重新打开它,问题就解决了。(叹气..)

我的文件夹结构

    tsconfig.json
    package.json
    bar/
         myfile.ts
    lib/
         (no file)

我的 tsconfig.json

   "compilerOptions": { ... },
   "include": [
    "bar/**/*",
    "lib/**/*"
   ],
   "exclude": [
    ".webpack/**/*",
    ".vscode/**/*"
   ]
   

3

3
任何遇到相同错误的人都应该尝试将“node modules”添加到排除选项中。
{
   "compilerOptions": {
     ...
   },
   "include": [
      "./src/**/*.ts"
   ],
   "exclude": [
      "./out.d.ts",
      "node_modules",
   ]
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接