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

Angular项目编译报错:payment-details.component.ts未在tsconfig配置

解决Angular中组件未被TypeScript编译的问题

Hey there, let's figure out why you're running into this compilation error while setting up routing for your Angular app. The root cause here is straightforward: your payment-details.component.ts file isn't being included in TypeScript's compilation pipeline, which is governed by your tsconfig.app.json configuration file in the src directory.

Here are the most common reasons and fixes for this issue:

  • Your component path isn't covered by the include array
    By default, Angular's tsconfig.app.json usually includes a rule like src/**/*.ts to cover all TypeScript files under the src folder. But if your component is in a nested directory like src/app/Payment/payment-details/, double-check that your include array actually covers this path. You can either use a broad pattern that includes all your app files, or explicitly add the component's directory:

    "include": [
      "src/**/*.ts", // This should cover all .ts files under src, including your component
      // Or if you want to be specific:
      // "src/app/Payment/payment-details/**/*.ts"
    ]
    
  • Your component directory is accidentally excluded
    Take a look at the exclude array in your tsconfig.app.json. If there's an entry that targets your Payment directory (like "exclude": ["src/app/Payment/**/*"]), TypeScript will skip compiling all files in that folder. Remove any such exclusion that affects your component's path.

  • You're using the files array and haven't added the component
    Some projects use the files array in tsconfig.app.json to explicitly list every file to compile (this is less common than using include). If that's your case, you'll need to add the full path to payment-details.component.ts to this array. For example:

    "files": [
      "src/app/Payment/payment-details/payment-details.component.ts",
      // ... other files you've listed
    ]
    

    That said, using include is generally better because it automatically picks up new files you add, so you don't have to update this list every time.

As a quick troubleshooting step, you can also try clearing Angular CLI's cache with ng clean, then re-run ng build or ng serve—sometimes cached state can cause unexpected issues like this.

内容的提问来源于stack exchange,提问作者Curious-programmer

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 07:45:31