-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic import of locales not available in Angular 13 #22154
Comments
@Rambou, the above mentioned behaviour is caused by a confirmed bug in Webpack. See webpack/webpack#13865 for which a workaround can be found highlightjs/highlight.js#3223 (comment). It's important to point out that using Webpack specific features such as magic comments are not supported by the Angular tooling team. The fact that the Angular CLI is using Webpack is an implementation detail which can change in the future. Duplicate of #22088 |
@alan-agius4 thanks for your answer. The workaround highlightjs/highlight.js#3223 (comment) just fixes the typescript error but the import of the locale still doesn't work because the webpack magic comments are not being applied that way. The solution to the issue is this one
|
But this is then very interesting, but how to do it then the "angular" way? because in our product we use: import( so how to solve that problem then? We need dynamic loading or else i need to really load all of the locales up front already? |
Here is what is currently working for me with v13. I use this in a library and I can verify that the consuming applications of this library are getting the appropriate locale files built. I only want certain locals included.
|
@geo242 answer worked for me. by adding the /node_modules/ in front of @angular/common |
@geo242 doesn't work in v13 for me
|
A relative path works for me (Angular 13 and Nx 13.4). import(
/* webpackInclude: /(it|en)\.mjs$/ */
/* webpackChunkName: "./assets/l10n/locales/[request]"*/
`../../../../../../node_modules/@angular/common/locales/${lang}.mjs`
) as Promise<{ default: unknown }> and it works also with @Rambou path: `@/../node_modules/@angular/common/locales/${lang}.mjs` |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Which @angular/* package(s) are the source of the bug?
common
Is this a regression?
Yes
Description
While in a previous version of angular, you could import locales and their extra's dynamically, it is impossible in angular 13. Below there is a sample of code with Webpack magic comments that lazy-load of locales was possible.
Now Webpack throws an error because
exports
attribute seems to be misconfigured inpackage.json
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Please provide the environment you discovered this bug in
Anything else?
No response
The text was updated successfully, but these errors were encountered: