Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'humanize' of undefined #4493

Closed
munkhorgil opened this issue Mar 11, 2018 · 9 comments
Closed

Cannot read property 'humanize' of undefined #4493

munkhorgil opened this issue Mar 11, 2018 · 9 comments

Comments

@munkhorgil
Copy link

When I set locale as mn it produces error if I use updateLocale, On the contrary If I use locale instead of updateLocale there is no error, but gives depreciation warning.
Code as follows

moment.updateLocale('mn', {
    relativeTime: {
        future: '%s дараа',
        past: '%s өмнө',
        s: 'саяхан',
        m: 'минутын',
        ...
    }
});

moment.locale('mn');

Environment:

  • Chrome
  • OSX
  • Node JS
  • React JS
  • Moment 2.17

Error:
Cannot read property 'humanize' of undefined

@ashsearle
Copy link
Contributor

Can you check if this problem still exists in 2.21.0, and if it does can you show a bit more code for us to reproduce.

(I tried the code you provided - with ... deleted - and it works fine.)

@munkhorgil
Copy link
Author

munkhorgil commented Mar 11, 2018

@ashsearle I've just upgraded to 2.21.0 error still show up here is my code

import React from 'react';
import ReactDOM from 'react-dom';
import { KnowledgeBase } from './containers';
import './sass/style.scss';
import TranslationWrapper from '../TranslationWrapper';
import moment from 'moment';

window.addEventListener('message', (event) => {
  // set locale moment
  moment.updateLocale('en', {
    relativeTime: {
      future: 'in %s',
      past: '%s ',
      s: 's',
      m: 'm',
      mm: '%d m',
      h: 'h',
      hh: '%d h',
      d: 'd',
      dd: '%d d',
      M: 'a mth',
      MM: '%d mths',
      y: 'y',
      yy: '%d y',
    },
  });

  moment.updateLocale('mn', {
    relativeTime: {
      future: '%s дараа',
      past: '%s өмнө',
      s: 'саяхан',
      m: 'минутын',
      mm: '%d минутын',
      h: '1 цагийн',
      hh: '%d цагийн',
      d: '1 өдрийн',
      dd: '%d өдрийн',
      M: '1 сарын',
      MM: '%d сарын',
      y: '1 жилийн',
      yy: '%d жилийн',
    },
  });

  moment.locale('mn');

  // render root react component
  ReactDOM.render(
      <TranslationWrapper>
        <KnowledgeBase />
      </TranslationWrapper>,
    document.getElementById('root'),
  );
});

@munkhorgil
Copy link
Author

munkhorgil commented Mar 12, 2018

@ashsearle There is no locale for mn so that I put moment.defineLocale('mn', ... ) instead of updateLocale now it works fine.

@munkhorgil
Copy link
Author

Unfortunately deprecation warning shows up @ashsearle

@munkhorgil munkhorgil reopened this Mar 12, 2018
@ashsearle
Copy link
Contributor

Which line of code triggers the deprecation warning? Which warning is it?

@munkhorgil
Copy link
Author

Warning as follows: deprecation warning use moment.update locale
moment.locale('mn')

@ashsearle
Copy link
Contributor

I'm not convinced you've given the right warning or line of code.

I suspect you're actually seeing:

Deprecation warning: use moment.updateLocale(localeName, config) to change an existing locale. moment.defineLocale(localeName, config) should only be used for creating a new locale See http://momentjs.com/guides/#/warnings/define-locale/ for more info.

You're trying to configure two locales. One already exists ('en') and one doesn't ('mn')

You should use updateLocale to modify the 'en' locale, and defineLocale for the 'mn' locale.

If you do that, does it get rid of the deprecation warning?

@marwahaha
Copy link
Member

@munkhorgil - try upgrading to 2.22.0 - we now support locale mn.

Please re-open if you still have problems.

@bhaskardabhi
Copy link

Using 2.27.0 still issue is there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants