我有一个包含多个应用程序(应用程序,开发等)的angular项目,最近我将其从Angular v8.2.3升级到了9,现在已经开始收到许多后续警告(关于不同的组件,这只是一个例子)
WARNING in {PATH_TO_PROJECT}\src\modules\dev\create-member\create-member.component.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.
root ts config:
{
"compileOnSave": false,
"compilerOptions": {
"allowJs": true,
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
// tslint bug isn't checking for no unused imports, their solution is to add this
// https://github.com/Microsoft/vscode-tslint/issues/70#issuecomment-241041929
"noUnusedLocals": true,
"noUnusedParameters": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
],
"plugins": [
{"name": "@angular/language-service"}
]
}
}
/ src tsconfig:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"module": "es2015",
"types": []
}
}
我确实设法通过在每个应用程序下添加一个单独的tsconfig并使其具有以下内容来在没有这些警告的情况下正常工作:
{
"extends": "../../tsconfig.json",
"files": [
"./{APP_NAME}.main.ts",
"../../polyfills.ts"
]
}
使用ng build --project应用程序,一切似乎都可以正常构建,但是当我添加--prod标志时,我收到许多关于组件无法识别的模板错误 例如
ERROR in src/modules/app/organizations/organization-data-budget-change/organization-data-budget-change.component.html:4:7 - error NG8002: Can't bind to 'formGroup' since it isn't a known property of 'form'.
[1]
[1] 4 <form [formGroup]="DataBudgetChangeForm" class="card-body" novalidate>
[1] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[1]
[1] src/modules/app/organizations/organization-data-budget-change/organization-data-budget-change.component.ts:11:15
[1] 11 templateUrl: 'organization-data-budget-change.component.html'
[1] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[1] Error occurs in the template of component OrganizationDataBudgetChangeComponent.
基本上,我只是想摆脱上面提到的警告,而且我不确定这是一个角度问题还是我的配置不正确
更新: 似乎通过上述tsconfig附加功能,在我的angular.json文件中将aot设置为false会使一切正常运行(这并不是真正的修复,因为我仍然想继续使用aot)。禁用常春藤也是一样
答案 0 :(得分:0)
按照升级页面上的说明进行操作后,我出现了一些错误。所以我删除了node_modules,清理了npm缓存并再次安装。
这些命令假定您正在使用npm。
rd /q /s node_modules (or equivalent command on your platform)
npm cache clean --force
npm install -g @angular/cli (optional if it already latest)
del package-lock.json (or equivalent command
on your platform)
npm install
ng add @angular/localize (in case it was not already added)
npm install --save-dev @angular/cli