首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误:在重新编译角13.1之后,您的应用程序或其依赖项之一似乎正在使用i18n

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

Stack Overflow用户
提问于 2021-12-12 10:56:56
回答 2查看 1.4K关注 0票数 0

我在做一个13.0.1的角度计划

我刚把它更新到13.1.0

我的package.json

代码语言:javascript
复制
{
  "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时,它开始时没有任何问题,但是每当我更改任何代码和重新编译的代码时,我都会在某些页面中得到以下错误!

代码语言:javascript
复制
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,在更新之前我的代码还好!

代码语言:javascript
复制
/***************************************************************************************************
 * 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
 */
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-12-14 04:08:50

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

代码语言:javascript
复制
// import '@angular/localize/init';
import '../node_modules/@angular/localize/init';
票数 1
EN

Stack Overflow用户

发布于 2022-10-24 13:35:16

我知道这个答案已经被回答了;然而,对我来说,另一个答案并不适用于第14角,但这是有效的:

代码语言:javascript
复制
import '@angular/localize/init'

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70322914

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档