I want to load this plugin "moment-range" for Moment which is in ES6 Format here: https://github.com/rotaready/moment-range/blob/master/lib/moment-range.js

They do also have it in this format too, not sure what to call it: https://github.com/rotaready/moment-range/blob/1effe5852e7d9312debc6ecb6de334b605bc9fb6/lib/moment-range.js

Their install docs are here: https://github.com/rotaready/moment-range

So I have my requirejs-config.js like this:

var config = {
map: {
    '*': {
        'moment-range': 'MyCompany_Mymodule/js/utils/moment-range'
    'shim': {
        'moment-range': {
            deps: ['moment']


and JS file:

    function (moment, momentrange) {

I have tried both versions, but the momentrange is not available inside the module (shows as undefined). I can access "moment" fine, but momentrange is undefined. (moment-range js file does show up if I look at sources under chrome).

Does anyone know the proper way to do this?

1 Answer 1


I was able to get it to work using this version: https://github.com/rotaready/moment-range/blob/1effe5852e7d9312debc6ecb6de334b605bc9fb6/lib/moment-range.js

I just wrapped the existing code with this:

define(['moment'], function(moment) {
    'use strict';

// file contents from: https://github.com/rotaready/moment-range/blob/1effe5852e7d9312debc6ecb6de334b605bc9fb6/lib/moment-range.js 
// but removed this line: const moment = require('moment');


Then when I called moment it had the range plugin added to it so I could use it like moment.range(). My requirejs-config.js code was correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.