Angular 5编译报错:index.ts未配置在tsconfig的files/include中
Alright, let's tackle this error you're facing after copying the Nebular auth UI component folder. The root issue here is that your TypeScript compiler doesn't know about the new index.ts file in your custom auth component directory—your current tsconfig.json doesn't specify which files to include in the compilation process.
Here's how to fix it:
Step 1: Update Your tsconfig.json
Add an include property to your configuration to explicitly tell TypeScript to compile your custom auth components, along with all your existing app code. Replace your current config with this:
{ "compileOnSave": false, "compilerOptions": { "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "target": "es5", "typeRoots": [ "node_modules/@types" ], "lib": [ "es2017", "dom" ], "plugins": [ { "name": "tslint-language-service"} ] }, "include": [ "src/**/*.ts", "src/app/@theme/components/auth/**/*.ts" ] }
What This Does:
"src/**/*.ts": This catches all.tsfiles in yoursrcdirectory and its subfolders—ensuring your entire app code gets compiled."src/app/@theme/components/auth/**/*.ts": Explicitly targets your custom auth component directory, making sure theindex.ts(and any other.tsfiles there) are included in the TypeScript build.
Step 2: Check for a tsconfig.app.json (If You're Using Angular)
Many Angular projects use a separate tsconfig.app.json file for app-specific compilation rules. If this exists in your project, you'll need to add the same include rules there too:
{ // ... existing compilerOptions "include": [ "src/**/*.ts", "src/app/@theme/components/auth/**/*.ts" ] }
Quick Sanity Check
Double-check that the path src/app/@theme/components/auth/index.ts actually exists—typos in file paths are a common culprit here!
Once you update your config, restart your development server (if it's running) to apply the changes. The TypeScript compiler should now recognize your custom auth component files and the error should disappear.
内容的提问来源于stack exchange,提问作者Umair Malik

