select2 + requirejs: Cannot bundle i18n files
Asked Answered
B

1

6

I've been trying to save some ajax calls on my production environment. For that, I have bundled and minified some of my scripts but I'm struggling with select2 and it's translation files.

I've included jQuery + bootstrap + (lots of deps) + select2 + select2 i18n files on a built.js and set the shim values (tho i don't think it's needed).

Both jquery and select2 are pasted before the i18n files.

Added the following config (on production environment):

requirejs.config({
    bundles: {
        'built': [
            'jquery',
            'bootstrap',
            'highcharts',
            'bootbox',
            'datatables',
            'datatables-bootstrap',
            'i18n',
            'moment',
            'knockout',
            'knockout-mapping',
            'pnotify',
            'pnotify.nonblock',
            'pnotify.desktop',
            'pnotify.buttons',
            'select2/select2',
            'select2/i18n/pt-BR',
            'select2/i18n/es',
            'select2/i18n/en'
        ]
    }
});

However, when I try to load my application with all minified resources I get an error on the console:

Uncaught TypeError: Cannot read property 'define' of undefined

On this line:

(function(){if(jQuery&&jQuery.fn&&jQuery.fn.select2&&jQuery.fn.select2.amd)var e=jQuery.fn.select2.amd;return e.define("select2/i18n/pt-BR",[],function()

After few seconds when waitSecondsTimeout expires:

Uncaught Error: Load timeout for modules: select2/i18n/pt-BR,select2/i18n/es,select2/i18n/en

Application works well without the built files.

Belisle answered 22/9, 2016 at 21:22 Comment(0)
H
0

I had a similar problem not sure what caused it, deferred loading, or browser using multiple threads to load up javascript, but I solved it by wrapping the i18n file function with this

(function(){if(jQuery&&jQuery.fn&&jQuery.fn.select2&&jQuery.fn.select2.amd){
                                                                           ^

Note the added accolade.

Then at the end of the file, before the last accolade I added

}
else {
    window.setTimeout(arguments.callee,10);
}})();
Hiawatha answered 24/10, 2017 at 10:9 Comment(1)
Man, you are guru. I had same error inside django-jet, in bundle.min.js. Once repaired node_modules/select2/.../en.js,.. before "gulp build", everything is ok. Thank you!Ent

© 2022 - 2024 — McMap. All rights reserved.