I couldn’t find what was wrong with the code, so I used a different code which I found on the internet and now the window is opening.
var file_frame;
$('#csv_file_button').on('click', function(event){
event.preventDefault();
if ( file_frame ) {
file_frame.open();
return;
}
// Create the media frame.
file_frame = wp.media.frames.file_frame = wp.media({
title: $( this ).data( 'File upload' ),
button: {
text: $( this ).data( 'Upload' ),
},
multiple: false // Set to true to allow multiple files to be selected
});
// When an image is selected, run a callback.
file_frame.on( 'select', function() {
// We set multiple to false so only get one image from the uploader
attachment = file_frame.state().get('selection').first().toJSON();
$('#csv_file').attr('value',attachment.url);
});
// Finally, open the modal
file_frame.open();
});