before bootstrap-datetimepicker.js on every page that uses the picker."}}]}]}

dianping/cat · critical · Error

momentjs is required

Error message

momentjs is required

What it means

This datetimepicker plugin (the Smalot/bootstrap-datetimepicker style factory wrapper here paired with an older picker) requires moment.js to be present. After the UMD factory check, the main IIFE re-checks typeof moment === 'undefined' and both alerts and throws. Without moment the picker cannot parse/format dates, so it refuses to initialize.

Source

Thrown at cat-home/src/main/webapp/assets/js/uncompressed/date-time/bootstrap-datetimepicker.js:48

    if (typeof define === 'function' && define.amd) {
        // AMD is used - Register as an anonymous module.
        define(['jquery', 'moment'], factory);
    } else {
        // AMD is not used - Attempt to fetch dependencies from scope.
        if (!jQuery) {
            throw 'bootstrap-datetimepicker requires jQuery to be loaded first';
        } else if (!moment) {
            throw 'bootstrap-datetimepicker requires moment.js to be loaded first';
        } else {
            factory(jQuery, moment);
        }
    }
}

(function ($, moment) {
    if (typeof moment === 'undefined') {
        alert("momentjs is requried");
        throw new Error('momentjs is required');
    };

    var dpgId = 0,

    pMoment = moment,

// ReSharper disable once InconsistentNaming
    DateTimePicker = function (element, options) {
        var defaults = {
            pickDate: true,
            pickTime: true,
            useMinutes: true,
            useSeconds: false,
            useCurrent: true,
            minuteStepping: 1,
            minDate: new pMoment({ y: 1900 }),
            maxDate: new pMoment().add(100, "y"),
            showToday: true,

View on GitHub (pinned to e815e74d4c)

Solutions

  1. Add <script src=".../moment.min.js"></script> before bootstrap-datetimepicker.js on every page that uses the picker.
  2. Verify moment loads (Network tab / typeof moment in console).
  3. If you do not need time picking, use the plain bootstrap-datepicker instead, which has no moment dependency.

Example fix

// before
<script src="bootstrap-datetimepicker.js"></script>

// after
<script src="moment.min.js"></script>
<script src="bootstrap-datetimepicker.js"></script>
Defensive patterns

Strategy: validation

Validate before calling

if (typeof window.moment === 'undefined') {
  console.error('moment.js missing: bootstrap-datetimepicker will not initialize.');
} else {
  $('#dt').datetimepicker();
}

Type guard

function datetimepickerDepsReady() {
  return typeof window.jQuery === 'function' && typeof window.moment !== 'undefined';
}

Prevention

When it happens

Trigger: Loading bootstrap-datetimepicker.js before moment.js; moment.js 404ing; a page where only the datepicker (not datetimepicker) is needed but this script is still included; using a bundler that does not resolve moment as an external.

Common situations: Template includes moment.js only on some pages while the datetimepicker script is included globally; aggressive concatenation reordering files alphabetically (bootstrap-datetimepicker before moment); CDN failure for moment.

Related errors


AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14). Data as JSON: /api/errors/b546f9ba3284f717. Report an issue: GitHub.