dot*_*pro 117 typescript angular-cli angular
我刚刚将 angular 更新为 latest 9.0.0-next.4。我没有使用路由,但在更新后突然我一直看到这个警告。如何删除此警告
WARNING in
src/war/angular/src/app/app-routing.module.ts是 TypeScript 编译的一部分,但未使用。仅将入口点添加到 tsconfig 中的“文件”或“包含”属性。
包.json
"dependencies": {
"@angular/animations": "^9.0.0-next.4",
"@angular/cdk": "^8.1.4",
"@angular/common": "^9.0.0-next.4",
"@angular/compiler": "^9.0.0-next.4",
"@angular/core": "^9.0.0-next.4",
"@angular/forms": "^9.0.0-next.4",
"@angular/material": "^8.1.4",
"@angular/platform-browser": "^9.0.0-next.4",
"@angular/platform-browser-dynamic": "^9.0.0-next.4",
"@angular/router": "^9.0.0-next.4",
"@ng-bootstrap/ng-bootstrap": "^5.1.0",
"bootstrap": "^4.3.1",
"hammerjs": "^2.0.8",
"moment": "^2.24.0",
"ng-image-slider": "^2.0.1",
"panzoom": "^8.1.2",
"rxjs": "~6.5.2",
"tslib": "^1.9.0",
"zone.js": "^0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.803.2",
"@angular/cli": "^8.3.2",
"@angular/compiler-cli": "^9.0.0-next.4",
"@angular/language-service": "^9.0.0-next.4",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "^5.0.0",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "^5.15.0",
"typescript": "^3.5.3"
}
Run Code Online (Sandbox Code Playgroud)
配置文件
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "esnext",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
}
}
Run Code Online (Sandbox Code Playgroud)
Ayy*_*ash 92
事实证明,您需要从“include”中删除这一行
"src/**/*.ts",tsconfig.app.json并且只在文件(main.ts 和 polyfills.ts)中保留入口点
emp*_*emp 46
我可以通过files在tsconfig.app.json. 这些文件是相对于tsconfig.app.json文件的。
"files": [
"main.ts",
"polyfills.ts"
]
Run Code Online (Sandbox Code Playgroud)
ZZZ*_*ZZZ 22
在从 Angular 8 升级到 Angular 9(包括 CLI 本地和全局)之后,我看到这些消息抱怨 environment.*.ts 文件,这些文件实际上在 angular.json 中提到了不同的构建。但是,我没有运行ng update它可能会使用以下内容更新 tsconfig.json,而是手动更新了 tsconfig.json。
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
Run Code Online (Sandbox Code Playgroud)
然后警告消失。
在 Visual Studio Professional 2019 中使用 Angular 9.1.x 更新 2020-05-27
不再需要上面的小块了。否则,它会导致规范测试代码对实际存在的模块抱怨“找不到模块”,因为ng test构建和运行良好,并且 ng 应用程序的构建和运行正常。显然,NG 中的某些内容在 9 和 9.1 之间发生了变化。
这是我现在工作的 tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2020",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
],
"skipLibCheck": true
}
}
Run Code Online (Sandbox Code Playgroud)
评论:
我只针对 Google Chrome 和 Safari,所以如果你想针对其他浏览器,你可能需要做相应的调整。
小智 18
今天更新到 Angular 9 并收到警告。我的解决方案是添加这个“文件”数组,路径中没有“src”。刚刚添加:
"files": [
"main.ts",
"polyfills.ts"
],
Run Code Online (Sandbox Code Playgroud)
我的完整 tsconfig.app.json 文件是:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"types": ["node"]
},
"files": [
"main.ts",
"polyfills.ts"
],
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}
Run Code Online (Sandbox Code Playgroud)
Sim*_*ver 18
我在 Angular 10 中被这些消息轰炸,以前从未见过它们。改变includes没有区别。
然后我找到了https://github.com/angular/angular/pull/36211。
这基本上与此问题中提出的错误相同,但对于ngtypecheck.ts文件(无论它们是什么,我都不确定!)
/home/circleci/ng/aio/src/main.ngtypecheck.ts 中的警告是 TypeScript 编译的一部分,但未使用。仅将入口点添加到 tsconfig 中的“文件”或“包含”属性。
在我看来,它实际上与@angular-builders/custom-webpack.
https://github.com/just-jeb/angular-builders/issues/781 其中一个问题刚刚打开。感谢/sf/answers/4380130611/指出这一点。
更新到 v10.0.1 为我修复了它,但最新的请参阅上述问题。
"@angular-builders/custom-webpack": "10.0.1" // as of today
Run Code Online (Sandbox Code Playgroud)
Mat*_*tts 15
这似乎很明显,但是对于您添加但尚未引用/导入到另一个文件的任何文件,您都会看到此警告。当您尝试编辑受警告影响的文件之一时,这将变得很明显,并且 Ivy 在编辑该文件后不会自动重新编译。一旦您将模块导入依赖文件并开始使用它,警告就会消失。
上面的答案可能与某些人有关,但我刚刚在这篇文章中描述的是我发出警告的根本原因。请注意,我的 tsconfig.json 或 tsconfig.app.json 中没有包含或文件数组,一旦我实际引用了项目中其他地方的文件,警告就会消失。
02-08-2020
离子 5+ Angular 9+ 应用程序。
注:见include小节。
tsconfig.app.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": []
},
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.d.ts"
],
"exclude": [
"src/**/*.spec.ts"
]
}
Run Code Online (Sandbox Code Playgroud)
只需添加 zone-flags.ts 并删除任何包含。
"files": [
"src/main.ts",
"src/polyfills.ts",
"src/zone-flags.ts"
]
Run Code Online (Sandbox Code Playgroud)
小智 5
tsconfig.app.json
"exclude": [
"src/**/*.spec.ts",
"src/test.ts",
"src/environments/environment.prod.ts"
]
Run Code Online (Sandbox Code Playgroud)
这段代码解决了这个问题。
| 归档时间: |
|
| 查看次数: |
83076 次 |
| 最近记录: |