Windows 11下Node.js执行npm run build遇TS18003错误如何修复?
问题场景
Windows 11系统下,在CMD执行npm run build时触发错误:error TS18003: No inputs were found in config file,相关配置如下:
package.json

tsconfig.json
{ "compilerOptions": { "target": "es2016", "module": "commonjs", "rootDir": "XSHOPPER-BACKEND", "moduleResolution": "node", "outDir": "build", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, "skipLibCheck": true } }

修复步骤
这个错误核心是TypeScript无法找到需要编译的.ts文件,按以下步骤排查修复:
校验目录结构:确认
XSHOPPER-BACKEND目录存在于tsconfig.json所在的同级路径下,且该目录内确实包含TypeScript源码文件(.ts后缀)。如果目录名称或路径有误,直接修正目录名或者调整tsconfig里的rootDir值。添加include配置:在tsconfig.json中补充
include字段,明确指定需要编译的文件范围,确保TypeScript能定位到源码:{ "compilerOptions": { "target": "es2016", "module": "commonjs", "rootDir": "XSHOPPER-BACKEND", "moduleResolution": "node", "outDir": "build", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, "skipLibCheck": true }, "include": ["XSHOPPER-BACKEND/**/*"] }这里的
**/*表示匹配XSHOPPER-BACKEND目录下所有子目录和文件。检查npm脚本:确认package.json中的
build脚本是正确调用tsc命令,比如如果脚本是"build": "tsc",要保证tsconfig.json在项目根目录;如果配置文件在其他路径,需指定路径:"build": "tsc --project ./config/tsconfig.json"。修正大小写问题:Windows系统不区分路径大小写,但TypeScript的
forceConsistentCasingInFileNames配置为true时,会强制校验路径大小写一致性,确认XSHOPPER-BACKEND的大小写和实际目录完全匹配。
内容的提问来源于stack exchange,提问作者user17281794

