Angular项目编译报错:payment-details.component.ts未在tsconfig配置
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
includearray
By default, Angular'stsconfig.app.jsonusually includes a rule likesrc/**/*.tsto cover all TypeScript files under thesrcfolder. But if your component is in a nested directory likesrc/app/Payment/payment-details/, double-check that yourincludearray 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 theexcludearray in yourtsconfig.app.json. If there's an entry that targets yourPaymentdirectory (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
filesarray and haven't added the component
Some projects use thefilesarray intsconfig.app.jsonto explicitly list every file to compile (this is less common than usinginclude). If that's your case, you'll need to add the full path topayment-details.component.tsto this array. For example:"files": [ "src/app/Payment/payment-details/payment-details.component.ts", // ... other files you've listed ]That said, using
includeis 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

