You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置tsc让routes目录被包含到编译输出目录中?

解决TypeScript编译时routes目录未生成到输出目录的问题

问题根源

你的tsconfig.json中include字段配置为[".."],这会尝试包含上级目录的所有文件,但由于routes目录和tsconfig.json处于同一层级,该配置无法正确识别当前目录下的routes/index.tsx,导致tsc编译时忽略了该文件。

修复步骤

1. 修正include配置

将include字段改为明确包含当前目录下所有.ts和.tsx文件,确保routes目录被覆盖:

"include": ["**/*.ts", "**/*.tsx"],

如果需要更精确的控制,也可以直接指定routes目录:

"include": ["./routes/**/*.tsx", "./**/*.ts"],

2. 保留合理的exclude配置

当前的exclude配置已经排除了node_modules和测试文件,无需修改:

"exclude": ["node_modules", "**/*.spec.ts"]

修改后的完整tsconfig.json示例

{
  "compilerOptions": {
    /* Language and Environment */  
    "target": "ES2022",
    "experimentalDecorators": true,
    /* Modules */ 
    "module": "CommonJS",
    "moduleResolution":"node",
    "outDir": ".randoms",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "baseUrl": ".",
    "paths": {  "@/*": ["./*"]  }
  },
  "include": ["**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules", "**/*.spec.ts"]
}

验证编译

修改配置后重新执行tsc命令,routes/index.tsx会被编译并输出到.randoms/routes/index.js目录下。

内容的提问来源于stack exchange,提问作者zain ul din

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 07:50:18