angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Dynamically loading locales broken for application build

Open jasedwards opened this issue 2 years ago • 0 comments

Command

build

Is this a regression?

  • [X] Yes, this behavior used to work in the previous version

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?

          /* webpackMode: "lazy-once" */
          /* webpackChunkName: "i18n-base" */
          /* webpackExclude: /(^en)\.js/ */
          /* webpackExclude: /\.d\.ts$/ */
          `@/../node_modules/@angular/common/locales/${localeId}.mjs`
        ).then(
          module => {
            registerLocaleData(module.default, localeId);
            resolve();
          },
          () => {
            import(
              /* webpackMode: "lazy-once" */
              /* webpackChunkName: "i18n-base" */
              /* webpackExclude: /(^en)\.js/ */
              /* webpackExclude: /\.d\.ts$/ */
              `@/../node_modules/@angular/common/locales/${localeId.split('-')[0]}.mjs`
            )
              .then(module => {
                registerLocaleData(module.default, localeId);
                resolve();
              })
              .catch((e) => {
                console.error(e);
                //Need to fall back to something
                return this.handleEnglishLocale(localeId, resolve, reject);
              });

Minimal Reproduction

ng build after having a service that tries to load locale dynamically.

Exception or Error

Failed to resolve module specifier '@/../node_modules/@angular/common/locales/it.mjs'

Your Environment

17.0.8

Anything else relevant?

No response

jasedwards avatar Jan 19 '24 17:01 jasedwards