TypeError: Cannot read property 'MediaFrame' of undefined

Viewed 1143

I am randomly getting this error when I edit a page, for example at /wp-admin/post.php?post=5323&action=edit

I don't think I need to include any code because this doesn't seem to reference any plugins. All of the problems are in /wp-includes/js

TypeError: Cannot read property 'MediaFrame' of undefined
    at Object.wp.media (/wp-includes/js/media-models.min.js?ver=5.4.1:2:1052)
    at new t (/wp-includes/js/dist/media-utils.min.js?ver=591443ff969b73a6db3bc4d8cc57722d:2:5719)
    at Ag (/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:63:107)
    at Vg (/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:89:442)
    at ph (/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:217:70)
    at lh (/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:126:409)
    at O (/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:121:71)
    at ze (/wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:118:14)
    at /wp-includes/js/dist/vendor/react-dom.min.js?ver=16.9.0:53:49
    at unstable_runWithPriority (/wp-includes/js/dist/vendor/react.min.js?ver=16.9.0:26:340)

WordPress version 5.4.1

1 Answers

The problem can be caused by a plugin, so it would be worth a try deactivating all of them and using a wordpress theme (like twentytwenty) to check if the problem is still occurs.

You should make sure that you have a footer.php in your theme, because the wp_enqueue_media() calls scripts there and maybe it cannot be loaded.


The TypeError sounds like not all the media scripts could be loaded on admin pages. You can try adding this to the end of your functions.php of your theme:

add_action('admin_enqueue_scripts', function()
{
    wp_enqueue_media();
});

An alternative way to write is the following, maybe it is a bit more readable. The code does exactly the same:

function load_my_wp_media() {
   wp_enqueue_media();
}
add_action( 'admin_enqueue_scripts', 'load_my_wp_media' );

This hook enqueue all media scripts, so 'MediaFrame' should no longer be undefined.

Related