How to use jQuery in WordPress 5.7+

(I’m using 5.7.2) This is all you have to use: const $ = jQuery.noConflict();. However, you have to make sure the file you load is loaded after jQuery to prevent timing issues. So either make jQuery a dependency of your script like this:

function _jf_load_scripts()
{
        wp_register_script('main', get_template_directory_uri() . '/build/js/main.bundle.js', array('jquery'), MY_VERSION, TRUE);
        wp_enqueue_script('main');
}
add_action('wp_enqueue_scripts', '_jf_load_scripts');

Or enqueue jQuery upfront, like this:

function _jf_load_scripts()
{
        wp_enqueue_script('jquery');

        wp_register_script('main', get_template_directory_uri() . '/build/js/main.bundle.js', array(), MY_VERSION, TRUE);
        wp_enqueue_script('main');
}
add_action('wp_enqueue_scripts', '_jf_load_scripts');

When your scripts load after jQuery, any of the used methods you describe above should work.