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

Uncaught TypeError: momentFn is not a function

Open djakuzey opened this issue 9 years ago • 13 comments

I've already got installed moment, react but getting this error on rendering Using latest version of react-datetime

Uncaught TypeError: momentFn is not a function
   at Object.localMoment (DateTime.js:372)
   at Object.getFormats (DateTime.js:122)
   at Object.getStateFromProps (DateTime.js:66)
   at Object.getInitialState (DateTime.js:55)
   at new eval (factory.js:789)
   at eval (ReactCompositeComponent.js:295)
   at measureLifeCyclePerf (ReactCompositeComponent.js:75)
   at ReactCompositeComponentWrapper._constructComponentWithoutOwner (ReactCompositeComponent.js:294)
   at ReactCompositeComponentWrapper._constructComponent (ReactCompositeComponent.js:280)
   at ReactCompositeComponentWrapper.mountComponent (ReactCompositeComponent.js:188)

I'm Submitting a ...

[x] Bug report
[ ] Feature request
[ ] Support request

djakuzey avatar Jul 12 '17 15:07 djakuzey

According to this article https://stackoverflow.com/questions/33704714/cant-require-default-export-value-in-babel-6-x the problem is in the wrong way of moment module requiring in file DateTime.js on line 6 . It should look like moment = require('moment').default, to work with Babel 6.

djakuzey avatar Jul 13 '17 08:07 djakuzey

@djakuzey answer is correct, it solved the problem for me.. Just wondering when will it be included on next release?

kenny26 avatar Sep 02 '17 10:09 kenny26

Apparently the changes also needs to be made on DaysView.js..

kenny26 avatar Sep 02 '17 12:09 kenny26

I'm using a fork to solve this issue as well for now. Side note, even though Babel 6 is being used, the tests fail when require('moment').default

rjdestigter avatar Nov 15 '17 14:11 rjdestigter

I also have this error. Since it has fix solution, when it could be fixed in release ?

smilexu avatar Nov 29 '17 14:11 smilexu

Hey people, sorry for the delay. It looks like this is still a problem.

I'm glad you found the problem and a solution. Does anyone know if this would break usage with Babel version <6?

simeg avatar Feb 11 '18 21:02 simeg

Although require('moment').default fixed module resolution in transpiled browser code, it would break usage in node.js. May be something like if (moment.default) { moment = moment.default; }?

kaid avatar Apr 02 '18 16:04 kaid

@simeg Maybe this could help: https://www.npmjs.com/package/babel-plugin-add-module-exports

martimarkov avatar May 08 '18 10:05 martimarkov

Why is this not yet fixed?

bminer avatar Jun 27 '18 16:06 bminer

I'd be happy to submit a PR for this if that would help. Basically would follow the suggestion posted by @kaid

Thoughts?

bminer avatar Jun 28 '18 15:06 bminer

I've just hit the problem and am wondering why this is still open. Apparently, not everybody is affected by this issue, otherwise I'd assume that it'd be fixed already.

AndreasEK avatar Jun 26 '19 13:06 AndreasEK

still cant get this to work on latest version with babel7 and webpack 4, is this library abandoned?

badgeek avatar Sep 05 '19 07:09 badgeek

@YouCanBookMe - Just curious if you are looking for maintainers. I can create a PR for this, but I don't want to do the work unless there is a good chance of it getting merged in.

bminer avatar Sep 09 '19 14:09 bminer