我从角度12移动到角度13,我有一个新的错误。因此,基本上我习惯于通过导入区域设置文件来加载用户的区域性。
const localeUri = `@angular/common/locales/${localeId}.js`;
return import(localeUri).then((module) => {
logger.debug("Culture Angular : '" + localeId + "'");
registerLocaleData(module.default);
}).catch((err) => {
logger.fatal("culture not defined for angular", err);
});此解决方案用于angular12,但不再用于angular13。Webpack找不到任何地点。我尝试了在github上找到的一些解决方案,但没有任何积极的结果
https://github.com/highlightjs/highlight.js/issues/3223#issuecomment-953337602
https://github.com/angular/angular-cli/issues/22154
有什么解决方案吗?
发布于 2022-01-03 14:52:36
通过更改我们导入的路径并将.js更改为.mjs,我成功地使其正常工作
之前:
import(
/* webpackInclude: /(de|de-AT|en|en-GB)\.js$/ */
`@angular/common/locales/${locale}.js`
).then((module) => {
registerLocaleData(module.default);
});之后:
import(
/* webpackInclude: /(de|de-AT|en|en-GB)\.mjs$/ */
`../../../../../../node_modules/@angular/common/locales/${locale}.mjs`
).then((module) => {
registerLocaleData(module.default);
});使用Angular 13.1.1和NX 13.4.2
这里已经提到了解决方案:https://github.com/angular/angular-cli/issues/22154
发布于 2021-11-15 14:25:40
您现在必须从@angular/common/locales/global/导入,不再需要registerLocaleData。
在角度13之前:
import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';
registerLocaleData(localeFr, 'fr-FR');角度为13:
import '@angular/common/locales/global/fr';
// and you can use fr-FR whenever you wanthttps://stackoverflow.com/questions/69946182
复制相似问题