Angular执行ng serve报错:仅向tsconfig的files/include添加入口文件
Angular项目ng serve报错:文件未在tsconfig中配置且构建卡住
问题情况
昨天执行ng serve运行项目一切正常,今天突然报错,提示“仅向tsconfig的'files'或'include'属性添加入口文件”。尝试过以下方案均无效:
- 修改tsconfig.app.json的include/exclude配置
- 重装Node.js、npm、Angular CLI(包括升级至14.2版本)
- 通过
ng new test33创建空白项目执行ng serve,仍出现相同报错,且构建到“生成浏览器应用包”步骤时卡住
测试环境版本
- Windows:10.0.19044.1766
- Node.js:16.14.0、16.17.1、18.10.0
- npm:对应Node.js自带版本
- Angular CLI:13.2.0-14.2
报错日志
C:\Users\THG\My Documents\apps\test33>ng serve √ Browser application bundle generation complete. Initial Chunk Files | Names | Raw Size styles.css, styles.js | styles | 175.24 kB | polyfills.js | polyfills | 174.53 kB | vendor.js | vendor | 173.64 kB | runtime.js | runtime | 6.51 kB | main.js | main | 1.02 kB | | Initial Total | 530.95 kB Build at: 2022-10-05T04:17:55.815Z - Hash: a99455c1b2851f77 - Time: 23545ms 警告:C:/Users/THG/My Documents/apps/test33/src/app/app-routing.module.ts属于TypeScript编译内容但未被使用。请仅向tsconfig的'files'或'include'属性添加入口文件。 警告:C:/Users/THG/My Documents/apps/test33/src/app/app.component.ts属于TypeScript编译内容但未被使用。请仅向tsconfig的'files'或'include'属性添加入口文件。 警告:C:/Users/THG/My Documents/apps/test33/src/app/app.module.ts属于TypeScript编译内容但未被使用。请仅向tsconfig的'files'或'include'属性添加入口文件。 警告:C:/Users/THG/My Documents/apps/test33/src/environments/environment.ts属于TypeScript编译内容但未被使用。请仅向tsconfig的'files'或'include'属性添加入口文件。 警告:C:/Users/THG/My Documents/apps/test33/src/main.ts属于TypeScript编译内容但未被使用。请仅向tsconfig的'files'或'include'属性添加入口文件。 警告:C:/Users/THG/My Documents/apps/test33/src/polyfills.ts属于TypeScript编译内容但未被使用。请仅向tsconfig的'files'或'include'属性添加入口文件。 ../../../Documents/apps/test33/src/main.ts - 错误:Module build failed (from ../../../Documents/apps/test33/node_modules/@ngtools/webpack/src/ivy/index.js): 错误:C:\Users\THG\Documents\apps\test33\src\main.ts缺失于TypeScript编译,请确保它已通过'files'或'include'属性配置到tsconfig中。 at C:\Users\THG\Documents\apps\test33\node_modules\@ngtools\webpack\src\ivy\loader.js:60:26 ../../../Documents/apps/test33/src/polyfills.ts - 错误:Module build failed (from ../../../Documents/apps/test33/node_modules/@ngtools/webpack/src/ivy/index.js): 错误:C:\Users\THG\Documents\apps\test33\src\polyfills.ts缺失于TypeScript编译,请确保它已通过'files'或'include'属性配置到tsconfig中。 at C:\Users\THG\Documents\apps\test33\node_modules\@ngtools\webpack\src\ivy\loader.js:60:26 ** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ ** × Failed to compile. - Generating browser application bundles...
自动生成的tsconfig文件内容
tsconfig.json
/* To learn more about this file see: https://angular.io/config/tsconfig. */ { "compileOnSave": false, "compilerOptions": { "baseUrl": "./", "outDir": "./dist/out-tsc", "forceConsistentCasingInFileNames": true, "strict": true, "noImplicitOverride": true, "noPropertyAccessFromIndexSignature": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, "sourceMap": true, "declaration": false, "downlevelIteration": true, "experimentalDecorators": true, "moduleResolution": "node", "importHelpers": true, "target": "es2017", "module": "es2020", "lib": [ "es2020", "dom" ] }, "angularCompilerOptions": { "enableI18nLegacyMessageIdFormat": false, "strictInjectionParameters": true, "strictInputAccessModifiers": true, "strictTemplates": true } }
tsconfig.app.json
/* To learn more about this file see: https://angular.io/config/tsconfig. */ { "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./out-tsc/app", "types": [] }, "files": [ "src/main.ts", "src/polyfills.ts" ], "include": [ "src/**/*.d.ts" ] }
tsconfig.spec.json
/* To learn more about this file see: https://angular.io/config/tsconfig. */ { "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./out-tsc/spec", "types": [ "jasmine" ] }, "files": [ "src/test.ts", "src/polyfills.ts" ], "include": [ "src/**/*.spec.ts", "src/**/*.d.ts" ] }
求助
有没有人遇到过相同问题或有解决方案?我的设备、Node.js或Angular CLI出了什么问题?
内容的提问来源于stack exchange,提问作者ManzTIHAGI
相关产品推荐
相关产品推荐

