wp_enqueue_script silently fails

I created a plugin which uses bootstrap datetimepicker. So i load corresponding js setting dependancies like this:

wp_enqueue_script('medapp-datetimepicker-js', $medapp_boot_timepicker_js, array(
                'jquery',
                'jquery-ui',
                'moment',
                'medapp-twitter-bootstrap-js'
            ));

 wp_enqueue_script('medapp-frontend-js', $medapp_script_js, array(
                    'jquery',
                  //  'medapp-datetimepicker-js',                   
                ),'',false);

If the line commented is on, of course in my js file i can't access datetimepicker and i have the following error when i try to instanciate the datetimepicker:

TypeError: jQuery(...).datetimepicker is not a function

So i uncomment the commented line, and then load of scripts silently fails (it seems nothing is loaded after the second wp_enqueue_script, but without any console error), and the page does not display entirely.

I know datetimepicker script is loaded correctly as i output all regegistered handlers like this:

function medapp_inspect_scripts() {
            global $wp_scripts;            
            foreach( $wp_scripts-queue as $handle ) {
                MEDAPI::getLogger("MEDAPP")-debug( $handle );
            }
        }

which correctly outputs the datetimepicker handler.

Any idea how i could debug this please ?

Topic wp-dependencies wp-enqueue-script Wordpress

Category Web


Thank you very much @WebElaine, i actually found the bug.

It was a cascading dependancy problem:

My datetimepicker enqueue was specifying a dependancy on moment.js, which is right, but moment was not enqueue as a script in my plugin. So i enqueued moment.js as other scripts right before enqueing datetimepicker, and it works. I am just surprised that i was able to enqueue datetimepicker with no error raised on dependancy (maybe another plugin is already enqueuing it ?).

Thank you very much.


Basic JS troubleshooting - strip it down to basics. Create a new script which either has a console.log('I am working') or alert('I am working') and enqueue it without any dependencies. If it works, enqueue it with your dependencies - still with your console or alert to easily check whether it's working. If it works, now you can do a really simple function with the datepicker you really want to use in your script. Once that works, put in your more complex custom code.

Another common thing to check - what version of jQuery does your version of Datetimepicker require, and what is loading in your version of WP? Perhaps they're not compatible.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.