Numeral-js icon indicating copy to clipboard operation
Numeral-js copied to clipboard

locales issue with react

Open bonesoul opened this issue 4 years ago • 3 comments

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')

bonesoul avatar Dec 27 '21 10:12 bonesoul

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

bozhidarc avatar Jan 27 '22 12:01 bozhidarc

any ideas on this?

bonesoul avatar Feb 04 '22 08:02 bonesoul

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.

NathanWalker avatar Feb 11 '22 03:02 NathanWalker