WordPress Javascript displaying an image Question

You need to call wp_enqueue_media() else the wp object won’t have a media option.

For example, go to WP Admin and pull up the JS console and type wp.media on the dashboard, it won’t work. Try again on the media page, and this time it will work.

https://codex.wordpress.org/Javascript_Reference/wp.media

To be able to use the JavaScript-API, you first have to init all the needed JavaScript-Libraries and Styles:

wp_enqueue_media();