错误:在重新编译angular 13.1之后,您的应用程序或其依赖项之一似乎正在使用i18n



我正在进行Angular项目13.0.1
我刚刚将其更新为13.1.0
package.json

{
"name": "gptk-total-system-angular",
"version": "00.09.17",
"scripts": {
"ng": "ng",
"start": "ng serve --open",
"start-es": "node ./replace.build.js && ng serve --open --configuration=es",
"build": "node ./replace.build.js && ng build --configuration=production --build-optimizer --optimization --extract-licenses=false",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^13.1.0",
"@angular/cdk": "^13.1.0",
"@angular/common": "^13.1.0",
"@angular/compiler": "^13.1.0",
"@angular/core": "^13.1.0",
"@angular/forms": "^13.1.0",
"@angular/material": "^13.1.0",
"@angular/platform-browser": "^13.1.0",
"@angular/platform-browser-dynamic": "^13.1.0",
"@angular/router": "^13.1.0",
"@angular/service-worker": "^13.1.0",
"@ckeditor/ckeditor5-angular": "^2.0.2",
"@ckeditor/ckeditor5-build-classic": "^23.1.0",
"angular2-text-mask": "^9.0.0",
"bootstrap": "^5.1.3",
"js-sha512": "^0.8.0",
"lodash-es": "^4.17.21",
"material-design-icons": "^3.0.1",
"mds.persian.datetime": "^1.4.2",
"rxjs": "^7.4.0",
"tslib": "^2.3.1",
"zone.js": "^0.11.4"
},
"devDependencies": {
"@angular-builders/custom-webpack": "^13.0.0",
"@angular-devkit/build-angular": "^13.1.1",
"@angular/cli": "^13.1.1",
"@angular/compiler-cli": "^13.1.0",
"@angular/language-service": "^13.1.0",
"@angular/localize": "^13.1.0",
"@types/bootstrap": "^5.1.6",
"@types/jasmine": "^3.10.2",
"@types/jasminewd2": "^2.0.10",
"@types/lodash-es": "^4.17.5",
"@types/node": "^16.11.9",
"codelyzer": "^6.0.2",
"jasmine-core": "^3.10.1",
"jasmine-spec-reporter": "^7.0.0",
"javascript-obfuscator": "^2.19.1",
"karma": "^6.3.9",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage-istanbul-reporter": "^3.0.3",
"karma-jasmine": "^4.0.1",
"karma-jasmine-html-reporter": "^1.7.0",
"protractor": "^7.0.0",
"replace-in-file": "^6.3.2",
"ts-node": "^10.4.0",
"tslint": "^6.1.3",
"typescript": "~4.4.4",
"webpack-obfuscator": "^3.5.0"
}
}

这是可以的,当我键入npm run start时,它开始时没有任何问题,但每当我更改任何代码并重新编译代码时,我都会在某些页面中出现以下错误!:

ERROR Error: Uncaught (in promise): Error: It looks like your application or one of its dependencies is using i18n.
Angular 9 introduced a global `$localize()` function that needs to be loaded.
Please run `ng add @angular/localize` from the Angular CLI.
(For non-CLI projects, add `import '@angular/localize/init';` to your `polyfills.ts` file.
For server-side rendering applications add the import to your `main.server.ts` file.)
Error: It looks like your application or one of its dependencies is using i18n.
Angular 9 introduced a global `$localize()` function that needs to be loaded.
Please run `ng add @angular/localize` from the Angular CLI.
(For non-CLI projects, add `import '@angular/localize/init';` to your `polyfills.ts` file.
For server-side rendering applications add the import to your `main.server.ts` file.)
at _global.$localize (core.mjs:28615)
at new PmEquipmentTaskCheckListHistoryComponent (pm-equipment-task-check-list-history.component.ts:32)
at NodeInjectorFactory.PmEquipmentTaskCheckListHistoryComponent_Factory [as factory] (pm-equipment-task-check-list-history.component.ts:22)
at getNodeInjectable (core.mjs:3549)
at instantiateRootComponent (core.mjs:10144)
at createRootComponent (core.mjs:12245)
at ComponentFactory.create (core.mjs:21566)
at ViewContainerRef.createComponent (core.mjs:22812)
at RouterOutlet.activateWith (router.mjs:2520)
at ActivateRoutes.activateRoutes (router.mjs:2160)
at resolvePromise (zone.js:1213)
at resolvePromise (zone.js:1167)
at zone.js:1279
at ZoneDelegate.invokeTask (zone.js:406)
at Object.onInvokeTask (core.mjs:25437)
at ZoneDelegate.invokeTask (zone.js:405)
at Zone.runTask (zone.js:178)
at drainMicroTaskQueue (zone.js:582)

我有如下polyfills.ts,在更新之前我的代码还可以!

/***************************************************************************************************
* Load `$localize` onto the global scope - used if i18n tags appear in Angular templates.
*/
import '@angular/localize/init';
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
*   1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
*   2. Application imports. Files imported after ZoneJS that should be loaded before your main
*      file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/guide/browser-support
*/
/***************************************************************************************************
* BROWSER POLYFILLS
*/
/**
* By default, zone.js will patch all possible macroTask and DomEvents
* user can disable parts of macroTask/DomEvents patch by setting following flags
* because those flags need to be set before `zone.js` being loaded, and webpack
* will put import in the top of bundle, so user need to create a separate file
* in this directory (for example: zone-flags.ts), and put the following flags
* into that file, and then add the following code before importing zone.js.
* import './zone-flags';
*
* The flags allowed in zone-flags.ts are listed here.
*
* The following flags will work for all browsers.
*
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
*
*  in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
*  with the following flag, it will bypass `zone.js` patch for IE/Edge
*
*  (window as any).__Zone_enable_cross_context_check = true;
*
*/
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
import 'zone.js';  // Included with Angular CLI.

/***************************************************************************************************
* APPLICATION IMPORTS
*/

polyfills.ts中,注释import '@angular/localize/init';并添加import '../node_modules/@angular/localize/init';

// import '@angular/localize/init';
import '../node_modules/@angular/localize/init';

我知道这个问题已经得到了回答;然而,对我来说,另一个答案对Angular 14不起作用,但它起作用了:

import '@angular/localize/init'

上面是在polyfills.ts文件中添加的,在抛出错误的项目中。

最新更新