react-widgets icon indicating copy to clipboard operation
react-widgets copied to clipboard

momentLocalizer is undefined in react-widgets-moment.js

Open lemiii opened this issue 10 years ago • 13 comments

I've tried this with both 3.0.0 and 3.1.3. The documentation states that I only need the following files in my script tags:

react-widgets/dist/react-widgets.js react-widgets/dist/react-widgets-moment.js

I've confirmed that these files are actually loaded and executed. The problem that I am running into is that when the DateTimePicker is used, I get the following error:

Error: [React Widgets] You are attempting to use a widget that requires localization (Calendar, DateTimePicker, NumberPicker). However there is no localizer set. Please configure a localizer.

I am loading react v0.14.6 and moment v2.11.1 before I load up the react-widgets scripts.

I'm also noticing that the following functions/objects are undefined:

  • momentLocalizer
  • window.momentLocalizer
  • document.momentLocalizer
  • ReactWidgets.momentLocalizer
  • ReactWidgets.utils.momentLocalizer
  • ReactWidgets.configure

Uncaught ReferenceError: momentLocalizer is not defined

In fact, I don't even see momentLocalizer in any of the source files. I did see an assignment of globalizeLocalizer to exports['default'], but am uncertain in how to access it.

My bower file has the following dependencies:

{
  "moment": "~2.11.1",
  "react": "0.14.6",
  "react-widgets": "~3.1.3"
}

I've also tried using the suggested globalize as well, but I started going down a rabbit hole trying to setup other dependencies for cldr and hunting down how to setup data for it with bowercc. I found that globalizeLocalizer did not exist either, even though the react-widgets/dist/react-widgets-globalize.js file was loaded.

lemiii avatar Jan 12 '16 19:01 lemiii

The localizer files don't actually create any globals instead they config themselves against the globally available ReactWidgets (https://github.com/jquense/react-widgets/blob/master/dist/react-widgets-moment.js#L112)

Any chance you can step into the code at that point and see whats going on? Perhaps you somehow have two instances of ReactWidgets loaded...

And yeah I am not sure you can even setup the new Globalize from bower, that project is sort of a rats nest of configs (we just use pre 1.0.0 which is dirt simple to setup)

jquense avatar Jan 12 '16 20:01 jquense

It appears that there is a function createWrapper that is setting up a dummy object if process.env.NODE_ENV is not equal to 'production'. The value I have is undefined. I also see that process.title === 'browser'. The get method is setup to always return an error unless it is in production.

The date-picker render is assigning format: getFormat(this.props) when _react2['default'].createEleemnt(_DateInput2['default'] is defined.

I do see two calls, but I am uncertain as to why this happens.

Error: [React Widgets] You are attempting to use a widget that requires localization (Calendar, DateTimePicker, NumberPicker). However there is no localizer set. Please configure a localizer. 

see http://jquense.github.io/react-widgets/docs/#/i18n for more info.
    at Object.get [as formats] (react-widgets.js:916)
    at Object.getFormat (react-widgets.js:886)
    at getFormat (react-widgets.js:7060)
    at render (react-widgets.js:6809)
    at 33.ReactCompositeComponentMixin._renderValidatedComponentWithoutOwnerOrContext (react.js:5941)
    at 33.ReactCompositeComponentMixin._renderValidatedComponent (react.js:5961)
    at 71.ReactPerf.measure.wrapper [as _renderValidatedComponent] (react.js:12346)
    at 33.ReactCompositeComponentMixin.mountComponent (react.js:5574)
    at 71.ReactPerf.measure.wrapper [as mountComponent] (react.js:12346)
    at Object.76.ReactReconciler.mountComponent (react.js:12971)

lemiii avatar Jan 12 '16 20:01 lemiii

The createWrapper thing is correct, if nothing replaces the wrapper it throws, which is what is happening. I mean specifically if you can debug whether that line I have linked above is hit. If this error happens before that then you are attempting to use a widget before the localizer is set, i.e the script executes.

jquense avatar Jan 12 '16 20:01 jquense

Ok, I believe it was rendering twice because the props were being assigned/updated, resulting in getFormat to be called again each time the component render method is called. I've got it setup to only have 1 call. Same problem though.

lemiii avatar Jan 12 '16 20:01 lemiii

Again the rendering multiple times is not the problem, Rendering ANY datepicker at all before the localizer script loads will rightfully cause an error.

I mean specifically if you can debug whether that line I have linked above is hit. If this error happens before that then you are attempting to use a widget before the localizer is set, i.e the script executes.

can you please try the above, thanks

jquense avatar Jan 12 '16 20:01 jquense

That line is not being called to setDateLocalizer. However, exports['default'] is being assigned when the file loads.

lemiii avatar Jan 12 '16 20:01 lemiii

Ok I think I found the issue... one sec

jquense avatar Jan 12 '16 20:01 jquense

I'm not sure if this is related, but I'm noticing there is a module missing in react-widgets-moment.js. I see functions under /* 0 */ through /* 3 */ - except for /* 2 */. Instead, there is just a comma without a value in the array. Also, moduleId in __webpack_require__ is 0, 1, and 3. 2 is never used.

lemiii avatar Jan 12 '16 21:01 lemiii

should be fixed in 3.1.4 (just released)

jquense avatar Jan 12 '16 22:01 jquense

one sec and i'll check

lemiii avatar Jan 12 '16 22:01 lemiii

I'm not seeing 3.1.4 in the releases here.

lemiii avatar Jan 12 '16 22:01 lemiii

https://github.com/jquense/react-widgets/releases/tag/v3.1.4

jquense avatar Jan 12 '16 22:01 jquense

Sweet! Confirmed as working. Thanks. :+1:

lemiii avatar Jan 12 '16 22:01 lemiii