BAE BAE - 7 months ago 25
Javascript Question

moment: Array.prototype.some called on null or undefined

Still stucked in the following problem. I did not have the problem last week and I did not change any codes:
I am using daterangepicker here:http://www.daterangepicker.com/#usage

My js codes:

const Backbone = require('backbone');
const dutils = require('dutils');
const FilterGroupView = require('./filterGroupView');
const _ = require('underscore');
const $ = require('jquery');
const moment = require('bootstrap-daterangepicker/moment');
require('bootstrap-daterangepicker');

const ranges = {
'Today': [moment().startOf('day'), moment()],
'Yesterday': [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')],
'Last 7 Days': [moment().subtract(7, 'days'), moment()],
'Last 30 Days': [moment().subtract(30, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')],
};

$('#dateForm').val(moment().subtract(7, 'days').format('YYYY-MM-DD HH:mm') + ' - ' + moment().format('YYYY-MM-DD HH:mm'));
console.log('ranges:' + JSON.stringify(ranges) ); // eslint-disable-line no-console
$('#dateForm').daterangepicker({
format: 'YYYY-MM-DD HH:mm',
minDate: new Date(2014, 0, 1),
maxDate: new Date(),
timePicker: true,
timePickerIncrement: 30,
showDropdowns: true,
ranges: ranges, // Here
}, (start, end, label) => {
$('#dateForm').val(start.format('YYYY-MM-DD HH:mm') + ' - ' + end.format('YYYY-MM-DD HH:mm'));
if (label !== 'Custom Range') {
this._relative_date = label;
} else {
this._relative_date = false;
}
});


log in console.log is below:

analytics.bundle.js?v=v1.71:2 ranges:{"Today":["2016-04-18T04:00:00.000Z","2016-04-18T17:51:28.384Z"],"Yesterday":["2016-04-17T04:00:00.000Z","2016-04-18T03:59:59.999Z"],"Last 7 Days":["2016-04-11T17:51:28.385Z","2016-04-18T17:51:28.385Z"],"Last 30 Days":["2016-03-19T17:51:28.385Z","2016-04-18T17:51:28.385Z"],"This Month":["2016-04-01T04:00:00.000Z","2016-05-01T03:59:59.999Z"],"Last Month":["2016-03-01T05:00:00.000Z","2016-04-01T03:59:59.999Z"]}


The above log shows that ranges is OK. The error in console.log is as following. If I removed " ranges: ranges, // Here" in the above code, the error will disappear. I cannot figure out why.

Uncaught TypeError: Array.prototype.some called on null or undefined


Details of the error:

c @ analytics.bundle.js?v=v1.71:16
Ue @ analytics.bundle.js?v=v1.71:17
me @ analytics.bundle.js?v=v1.71:17
n.setOptions @ analytics.bundle.js?v=v1.71:16
n @ analytics.bundle.js?v=v1.71:16
(anonymous function) @ analytics.bundle.js?v=v1.71:16
vt.extend.each @ commons.bundle.js?v=v1.71:14
vt.fn.vt.each @ commons.bundle.js?v=v1.71:14
$.fn.daterangepicker @ analytics.bundle.js?v=v1.71:16
t.exports.i.View.extend.initialize @ analytics.bundle.js?v=v1.71:2
e.View @ commons.bundle.js?v=v1.71:31
n @ commons.bundle.js?v=v1.71:32
t.exports.i.View.extend.initialize @ analytics.bundle.js?v=v1.71:1
e.View @ commons.bundle.js?v=v1.71:31
n @ commons.bundle.js?v=v1.71:32
(anonymous function) @ analytics.bundle.js?v=v1.71:1
h @ commons.bundle.js?v=v1.71:24
c.fireWith @ commons.bundle.js?v=v1.71:24
vt.extend.ready @ commons.bundle.js?v=v1.71:24
c @ commons.bundle.js?v=v1.71:14


Any suggestion will be welcomed, including whether the question should be downvoted or not? clear or not? Thanks

UPDATE

part of package.json:

"dependencies": {
"backbone": "^1.2.0",
"bootstrap": "^3.3.4",
"bootstrap-daterangepicker": "git://github.com/dangrossman/bootstrap-daterangepicker.git#v1.3.21",
"bootstrap-notify": "^3.1.3",
"css-loader": "^0.12.1",
"datatables": "git://github.com/DataTables/DataTables.git#1.10.7",
"expose-loader": "^0.6.0",
"extract-text-webpack-plugin": "^0.8.0",
"file-loader": "^0.8.1",
"html-loader": "^0.3.0",
"imports-loader": "^0.6.3",
"jquery": "^1.11.0",
"jquery-ui": "^1.10.5",
"style-loader": "^0.12.2",
"underscore": "^1.8.3",
"url-loader": "^0.5.5"
}


UPDATE

See the answer by Greg and here https://github.com/moment/moment/issues/3124

1, Add "moment": "^2.9.0" to package.json

2, Use const moment = require('moment'); to import moment.

Problem solved.

Answer

The issue appears to be coming from moment 2.13.0 which got released 11 hours ago from now. I assume your date picker is using moment as a dependency.

In the meantime...this should temporarily resolve your issue by downgrading the version. npm uninstall moment npm i moment@2.12.0

Update: I created an issue to track this. https://github.com/moment/moment/issues/3124

Comments