onefinestay / react-daterange-picker

Other
563 stars 208 forks source link

Uncaught TypeError: _moment2.default.range is not a function #66

Closed nickbrit closed 6 years ago

nickbrit commented 8 years ago

I get this error after reinstall npm module.

dphaener commented 8 years ago

:+1: Me too

moimikey commented 8 years ago

pedestrian question... BUT.... do you have moment and moment-range imported

AlanFoster commented 8 years ago

@nickbrit Are you still facing this issue?

rynonl commented 8 years ago

I am seeing this as of today. Any updates?

timaschew commented 8 years ago

Have the same issue when using the module from npm. But if I used the source from github it seems to work. Also find out it's not suitable if you want only a single picker. So I switched now to https://hacker0x01.github.io/react-datepicker/ it works perfect with redux-form

szubtsovskiy commented 8 years ago

I get the similar problem in my CI environment but not when I am running the app locally. In both cases I use production build of JS bundle. It is obfuscated (thanks UglifyJS), so the message is a little bit different but after investigation it becomes obvious that I've run into the same issue.

It looks like this statement:

require('moment-range');

which comes after this one:

var _moment2 = _interopRequireDefault(_moment);

does not actually change the _moment2["default"] instance in some circumstances.

My CI environment is Codeship (Ubuntu) and this error is 100% reproduced there when I am running my integration tests. Both when app is deployed locally (OS X) and on production (a droplet on DigitalOcean with Ubuntu) there is no problem.

Apparently there is no dependency on Node or NPM. I tried different versions and got the same result.

I suspect that there is some difference in JS engines which are used in Chrome and Firefox on different operating systems. I get similar symptoms in both browsers. My conclusion is that Chrome/Firefox process JS code generated by Webpack differently under different operating systems. It explains all symptoms but does not unfortunately give a clue how to fix it. :-(

Any ideas someone? Except for switching to another plug-in?

szubtsovskiy commented 8 years ago

I have just tested it. Apparently it depends on the operating system but not the way I thought.

When bundle is generated under OS X it works even when the app is viewed in Chrome under Ubuntu (at least my integration test passed successfully). When bundle is generated under Ubuntu (in my setup) I get the error mentioned in the issue.

It looks like an issue in Webpack rather than in moment-range.

szubtsovskiy commented 8 years ago

Well, using a fresh install definitely helps. Dependency cache was my enemy, now the problem is gone completely.

yrik commented 8 years ago

hm... have the same issue on ubuntu, on mac os it's ok.

AlanFoster commented 8 years ago

@yrik if you are still having issues, would you mind specifying what version of moment range you have in your mac and Ubuntu installs

AlanFoster commented 8 years ago

Also ensuring that your babel loader isn't accidentally being run over third party dependencies would be a good sanity check too

SimeonC commented 7 years ago

I just had this issue and it ended being resolved when I deleted node_modules, npm cache clear and npm install. Then there are no issues for some odd reason...

kukuruznik commented 7 years ago

I don't use react-daterange-picker but ran into this same issue (symptoms exactly as described by @szubtsovskiy). Reinstalling the dependencies (as described above) and rebundling helped.

Maxwin-z commented 7 years ago

When I use yarn, this error occurs. delete node_modules and npm install solve the problem.

Plazmaz commented 6 years ago

Still having this issue, none of the above fixes are working for me.

butsjoh commented 6 years ago

For anyone still landing on this. It was fixed for us if you properly extend moment with moment range (see moment range docs)

import Moment from 'moment'
import { extendMoment } from 'moment-range'

const moment = extendMoment(Moment);
AlanFoster commented 6 years ago

This should be fixed now by the latest version, please open a new issue if this is still happening after upgrading :+1: