question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$localize is not a function with Angular 14 build

See original GitHub issue

Bug description:

After upgrading to Angular 14, the Ngb Pagination component breaks with the error TypeError: $localize is not a function, but only in production build, it works in dev-mode.

This seems to be cause by some incompatibility of the @angular/localize library between the main build and this third party component build.

It’s like this polyfill doesn’t have any affect anymore: import '@angular/localize/init';

Versions of Angular, ng-bootstrap and Bootstrap:

Tried with ng-bootstrap 13.0.0-beta.1 and 12.x

Angular: 14.0.5 ng-bootstrap: 13.0.0-beta.1 Bootstrap: 4.5

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

2reactions
St1ccommented, Aug 23, 2022

Following discussions here: https://github.com/angular/angular-cli/issues/23781 on the same issue:

It seems that if you put “not ios_saf 12.2-12.6” to the end of .browserlistrc , then Angular compiles just fine.

I spent quite some time debugging it, the problem seems to be, that for legacy browsers compiler creates this compiled javascript code:

const i18n_1 = $localize(_t2 || (_t2 = _2``:@@ngb.alert.close:Close``));

In the compiled code _2 is defined as:

let _2 => t => t;

which causes problems, as $localize function should be used as tag function for template literals, where it expects messageParts: TemplateStringsArray as argument, but here it receives plain string. Removing " ios_saf 12.2-12.6" from browser compatibility list translates all custom IDs just fine.

1reaction
St1ccommented, Jul 12, 2022

I don’t think that’s the solution .browserlistrc is essential file for angular compiler. It says to the compiler which browsers should be supported, and then the compiler compiles Javascript files in compliance with that configuration.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular $localize is not a function - Stack Overflow
So this was WebStorm trying to be helpful. It had added the following line to the top of my ts file import {...
Read more >
$localize Global Import Migration - Angular
@angular/localize is a new package that supports i18n of messages in Ivy applications. This package requires a global $localize symbol to exist. The...
Read more >
Add the localize package - Angular
To add the @angular/localize package, use the following command to update the package. json and polyfills. ts files in your project.
Read more >
angular/localize
The @angular/localize package exposes the $localize function in the global namespace, which can be used to tag i18n messages in your code that...
Read more >
Ahead-of-time (AOT) compilation - Angular
Compiling your application during the build process provides a faster rendering in the ... The AOT compiler does not support function expressions and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found