我刚刚升级到 Angular 18,升级时收到以下警告
ng serve
:
▲ [WARNING] Polyfill for "@angular/localize/init" was added automatically. [plugin angular-polyfills]
In the future, this functionality will be removed. Please add this polyfill in the "polyfills" section of your "angular.json" instead.
angular.json
"build": {
"builder": "@angular-devkit/build-angular:browser-esbuild",
"options": {
"outputPath": "dist/MyClientApp",
"main": "src/main.ts",
"index": "src/index.html",
"polyfills": [
"src/polyfills.ts"
],
"tsConfig": "tsconfig.app.json",
polyfills.ts 包含行:
...
import '@angular/localize/init';
...
可能缺少什么?我在 `package.json' 中有 "@angular/localize": "^18.0.3",
将
"@angular/localize/init"
添加到 polyfills
中的 angular.json
数组中。
然后,如果您的 polyfills 文件仅包含
import '@angular/localize/init';
,则可以将其删除。 当我执行此操作时,警告消失了。