0

Without using optimization, application is working fine. But with optimization (minifying JS), the minified file throws "undefined is not a function" when loading homepage.

The issue is : in the main config file, i am using like below which creates loading problem in the line -- new controller() - undefined.

domReady(function() {

        if (domReady) {
    calendar.controller = new controller();
    if (Backbone) {
                Backbone.history.start();
            }
        }
    });

My build.js is below:

({
    'baseUrl': './',
    'dir': '../build/js',
    'paths': {
        'jquery': 'require-jquery',
        'underscore': 'lib/lodash.min',
        'backbone': 'lib/backbone-min',
        'mustache': 'lib/mustache',
        'bootstrap': 'lib/bootstrap.min',
        'fullcalendar': 'lib/fullcalendar.min',
        'controller': 'calendar/controllers/home_controller',
        'jqueryui':'lib/jquery-ui.min',
        'moment':'lib/moment.min',
        'customscroll':'lib/jquery.mCustomScrollbar',
        'mousewheel':'lib/jquery.mousewheel.min',
        'validate':'lib/jquery.validate.min',
        'datatable':'lib/jquery.dataTables.min',
        'blockUi':'lib/jquery.blockUI',
        'fileupload':'lib/fileuploader'
    },
    'shim': {
        'underscore': {
            'exports': '_'
        },
        'backbone': {
            'deps': ['jquery','underscore'],
            'exports': 'Backbone'
        },
        'bootstrap': {
            'deps': ['jquery'],
            'exports': 'jQuery.fn.alert'
        },
        'fullcalendar': {
            'deps': ['jquery']            
        },
        'jqueryui': {
            'deps': ['jquery']            
        },
        'customscroll': {
            'deps': ['jquery']            
        },
        'mousewheel': {
            'deps': ['jquery']            
        },
        'validate': {
            'deps': ['jquery']            
        },
        'datatable': {
            'deps': ['jquery']            
        },
        'fileupload': {
            'deps': ['jquery','jqueryui']            
        },
        'blockUi': {
            'deps': ['jquery']            
        },
        'controller': {
            'deps': ['backbone','fullcalendar','jqueryui','moment','customscroll','mousewheel','validate','datatable','blockUi','fileupload']
        }       

    },
    'locale': 'en-us',
    'optimize': 'uglify',
    'inlineText': true,
    'modules': [

        {
            'name': 'calendar/controllers/home_controller',
            'exclude': ['jquery']

        }

    ]
})

RequireJS version: 2.1.1.

1 Answer 1

2

It seems the optimizer is not finding your shim config. You will need to specify it using the mainConfigFile build option.

mainConfigFile: 'path/to/main.js'

More information on this config option can be found in require.js API doc - Main config file:

You should use the mainConfigFile build option to specify the file where to find the shim config. Otherwise the optimizer will not know of the shim config. The other option is to duplicate the shim config in the build profile.

As you already have it in your build profile, try the other way around.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, I tried as mentioned but i got an error: Error: The config in mainConfigFile <<PATH TO MAIN.JS>> cannot be used because it cannot be evaluated correctly while running in the optimizer. Try only using a config that is also valid JSON, or do not use mainConfigFile and instead copy the config values needed into a build file or command line arguments given to the optimizer. at Function.build.createConfig (/node_modules/requirejs/bin/r.js:14836:23). Also i copied the shim part alone from main.js into the build file and still facing the same issue.
I don't see in your shim where are you exporting object calendar? Where is it defined?
Yes, yes yes! Mine... mainConfigFile: '../app.js'

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.