-
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
Dynamically loading locales broken for application build #26904
Comments
The previously mentioned pattern was never officially supported since it was a feature specific to Webpack. Esbuild necessitates that imports be statically analyzable for processing. Nevertheless, you can achieve the desired outcome by referencing each locale lazily in a manner compatible with all bundlers. The following is equivalent to what Webpack was doing during the build process. function loadLocale(locale: string) {
return {
'en': () => import('@angular/common/locales/en'),
'fr': () => import('@angular/common/locales/fr'),
'de': () => import('@angular/common/locales/de'),
}
}
|
You could also do something like const localeData = await import(`../node_modules/@angular/common/locales/${localeId}.mjs`); |
Hey, based on my understanding how building works your first suggestion will work similar to what webpack does
but could you explain a bit more solution from your last comment?
Won't esbuild generate as many chunks as there are locales in |
For the moment I moved on to other issues. I don't think it's reasonable to have to manually import 250 cultures as we are an actual enterprise application that has to work globally. It is too bad something could not have been done on angular's side to actually make what I assume is a common functionality supportable. I did try ../node_modules... but no matter what path I try it either fails during build time or during runtime. |
@jasedwards FWIW we're investigating using the Intl API to drop the requirement for those locale files. |
this is not just about the locales that angular ships but any kind a comment about that, the thing is that now you need to hard code languages or locales, if that are 10 or 20 then it is doable As you can read in the above comment, i left angular to be dynamic (because of the many files and because angular at least is already a esm module, not a commonjs that needs to be wrapped). besides that i also need to tweak the server side because mjs files that are now downloaded don't have by default the correct mime type set... So not supporting dynamically loading of modules based does cause code explosion and maintenance nightmare.. |
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. |
Command
build
Is this a regression?
The previous version in which this bug was not present was
16
Description
Since angular 2 came out there have been ongoing discussions about the best way to load locales if you don't know the locale ahead of time. For example, my company supports over 200 locales so importing each one at the top of the file is not realistic. The most recent accepted workaround was to do the below. Now with esbuild this no longer works. Is there an accepted way to do this now?
Minimal Reproduction
ng build after having a service that tries to load locale dynamically.
Exception or Error
Your Environment
Anything else relevant?
No response
The text was updated successfully, but these errors were encountered: