adamwdraper / Numeral-js

A javascript library for formatting and manipulating numbers.
http://numeraljs.com
MIT License
9.65k stars 926 forks source link

locales issue with react #766

Open bonesoul opened 2 years ago

bonesoul commented 2 years ago

i can use the numeral.js within my reactt/next.js project but when i try to use a locale, getting the error:

  numeral.locale('tr');

 > TypeError: Cannot read properties of undefined (reading 'abbreviations')
bozhidarc commented 2 years ago

With Angular 13 is the same. If you try to get all registered locales you will see that only 'en' is loaded.

bonesoul commented 2 years ago

any ideas on this?

NathanWalker commented 2 years ago

I ran into similar and noticed something due to way this library is setup - as I was using it in pure esm codebase (ng 13+). When using alongside @types/numeral like this:

import { locale, register } from 'numeral';
import { localeFormat } from './utils';

register('locale', 'nl', localeFormat());
locale('nl');

Would throw this error everytime:

TypeError: Cannot read property 'nl' of undefined

However when used like this:

import * as numeral from 'numeral';
import { localeFormat } from './utils';

numeral.register('locale', 'nl', localeFormat());
numeral.locale('nl');

Everything worked fine.