在 TypeScript 的配置文件中找不到输入 [已解决]

在 TypeScript 的配置文件中找不到输入

No inputs were found in config file in TypeScript

当我们尝试构建一个不包含任何 TypeScript 文件的项目时,会出现错误“No inputs were found in config file”。

.ts要解决该错误,请在项目的根目录中添加一个带有扩展名的空文件,并在必要时重新启动 IDE。

配置文件中未找到任何输入

tsc # error TS18003: No inputs were found in config file. # Specified 'include' paths were '["**/*"]' and # 'exclude' paths were '["node_modules"]'.

您需要做的第一件事是确保您的项目至少包含一个带.ts扩展名的文件。

如果没有,您可以创建一个带有.ts扩展名的空文件来消除错误。

placeholder.ts创建一个名为以下内​​容的文件。

占位符.ts
export {};

在包含的目录中创建文件

include如果您已在文件中设置数组tsconfig.json,请确保在指定目录中创建文件。

tsconfig.json文件
{ "compilerOptions": { // ... your options }, "include": ["src/**/*"], "exclude": ["node_modules"] }

例如,上面文件include中的数组tsconfig.json在目录中查找文件src,因此您必须在
src.

如果您尚未设置include数组,请在项目的根目录(在 旁边tsconfig.json)中创建占位符文件。

重新启动您的 IDE 和开发服务器

如果项目中已有文件,请重新启动 IDE 和 TypeScript 服务器。

VSCode often glitches and needs a reboot. In that case, open a file with a .ts
or .js extension and restart the editor for it to pick it up.

Make sure you haven’t excluded all files from compilation #

Another thing that causes the error is if you add all the files in your
TypeScript project to the exclude array by mistake.

tsconfig.json
{ "compilerOptions": { // ... your options }, "include": ["src/**/*"], "exclude": ["node_modules"] }

If you don’t set the include
array setting it defaults to ** if the files setting is not specified,
otherwise an empty array [].

Make sure to only exclude the files that you want to filter out. If you have an exclude pattern that matches all of the files in your project, the error occurs.

Most of the time, TypeScript just needs an entry point for your project to be
able to compile successfully and solve the error.

Create a tsconfig.json file in your project’s root directory #

If you don’t use TypeScript in your project, but still get the error and a
restart of your IDE doesn’t help things, you can create a tsconfig.json file
in your project’s root directory to simply silence the error.

tsconfig.json
{ "compilerOptions": { "allowJs": false, "noEmit": true }, "exclude": ["src/**/*", "your-other-src/**/*"], "files": ["placeholder.ts"] }

And create a placeholder.ts file right next to the tsconfig.json file.

placeholder.ts
export {};

Restart your IDE and the error should be resolved.

The tsconfig.json file from the example looks to exclude all of your source
files from compilation and just needs a single file as an entry point
(placeholder.js) in the example.

这个文件的全部意义tsconfig.json在于消除不使用 TypeScript 的项目中的错误。