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

能否调整tsconfig.app.json与tsconfig.spec.json的存放路径至src/config?

Can I Relocate tsconfig.app.json and tsconfig.spec.json to src/config?

Absolutely, you can move these TypeScript configuration files to src/config—the error you’re hitting usually comes from two key issues: misconfigured relative paths in the moved files, or build/tools expecting the configs in their default root-level locations. Let’s walk through the fix step-by-step, no CLI tools required:

1. Fix the Root tsconfig.json’s extends Path

First, double-check your root tsconfig.json to ensure it points correctly to the new location of your config files (you already started this, but it’s worth verifying the path syntax):

{
  "extends": "./src/config/tsconfig.app.json",
  // Rest of your root config settings...
}

If your root config also extends tsconfig.spec.json, update that path to ./src/config/tsconfig.spec.json too.

2. Update Relative Paths in the Moved Config Files

This is the most common cause of errors. When you move tsconfig.app.json to src/config, all paths in its include, exclude, and compilerOptions (like outDir or baseUrl) are now relative to its new folder, not the project root. Here’s how to adjust them:

Example: Updated tsconfig.app.json (in src/config)

{
  "compilerOptions": {
    "outDir": "../../dist/out-tsc/app", // Relative path to root-level dist folder
    "baseUrl": "../../src", // Points back to the src directory
    // Rest of your compiler options...
  },
  "include": ["../**/*.ts", "../**/*.d.ts"], // Targets all TS files in src/
  "exclude": [
    "../../node_modules", // Relative path to root node_modules
    "../**/*.spec.ts" // Excludes test files from this app config
  ]
}

For tsconfig.spec.json, adjust its paths similarly—its include should target test files, e.g., "../**/*.spec.ts", and update outDir to point to the correct test output folder relative to src/config.

3. Explicitly Point Your Build Tool to the New Configs

Most build tools (like Webpack, Rollup, or Babel) default to looking for tsconfig.app.json in the project root. You’ll need to tell them where to find your relocated files.

For example, in a Webpack config using ts-loader:

module.exports = {
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: [
          {
            loader: "ts-loader",
            options: {
              configFile: "./src/config/tsconfig.app.json" // Path to your moved config
            }
          }
        ]
      }
    ]
  }
};

Adjust this snippet to match your specific build tool’s syntax if you’re using something else (like Vite or Rollup).

Once you’ve made these adjustments, restart your project—your configs should now load correctly from src/config without errors.

内容的提问来源于stack exchange,提问作者Bruno Dulcetti

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:33:19