11

Due to Angular update, I have problem with locales.

For now:

import localePl from '@angular/common/locales/pl';
registerLocaleData(localePl);

It's working but causes an error:

WARNING in app.module.ts depends on @angular/common/locales/pl. CommonJS or AMD dependencies can cause optimization bailouts.

Where does it work?

  1. I provide LOCALE_ID with value pl-PL
  2. And use DatePipe in HTML. (variable | date) - variable is equal to new Date()

Tested ways:

1)

import localePl from '@angular/common/locales/global/pl'; registerLocaleData(localePl, 'pl-PL');

Error:

'Cannot read property '0' of undefined' for pipe

In code: variable | date

Where variable is equal to new Date()

2) If I completely remove registerLocaleData

Error:

Missing locale data for the locale "pl-PL".' for pipe 'DatePipe'

Thomas Banderas
  • 1,681
  • 1
  • 21
  • 43

1 Answers1

19

I had same issues, to resolve that I, in my app.module:

add

import '@angular/common/locales/global/pl

remove

import localePl from '@angular/common/locales/pl';

and remove "registerLocaleData" function, kept the LOCALE_ID provider setting.

I hope works for you too.

  • Hmm, this is working for me too. Do you know why I have to use the global import instead of the other way? – aventic Sep 10 '20 at 17:36
  • Can confirm this is working for Angular 10.1.6 in strict mode. I was using the code form the original question initially with Angular 10.x without strict mode and it worked. But at some point (either after upgrading Angular or after enabling strict mode), only this would work. I guess it's in line with the official Angular Doc: https://angular.io/guide/i18n#import-global-variants-of-the-locale-data – mmey Oct 23 '20 at 20:33