'Failed to resolve module specifier "three" - Working Three/Wordpress Integration Suddenly Failed

I manage a WordPress website which uses a Three.js animation on the homepage. I built this site months ago and everything had been working perfectly fine - I even showed it to someone a week ago and nothing was amiss. Yesterday, I check the site and find that Three is not loading, and that I have this in the console:

Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../".

I don't have a line or even file to reference, the error is logged coming from the first line of the root domain. I want to emphasize that I had changed absolutely nothing about the set-up. I hadn't even updated to WP 5.9 yet. This is how I had originally set things up. Sorry if it's not best practices, but I want to emphasize that it did in fact work fine. Enqueuing animation javascript file and defining its type as "module":

function my_custom_scripts() {
    wp_enqueue_script( 'gsap', 'https://cdnjs.cloudflare.com/ajax/libs/gsap/3.7.0/gsap.min.js', array( 'jquery' ), '', true);
    wp_enqueue_script( 'scrolltrigger', 'https://cdnjs.cloudflare.com/ajax/libs/gsap/3.7.0/ScrollTrigger.min.js', array( 'gsap' ), '', true);
    wp_enqueue_script( 'custom-animations', get_stylesheet_directory_uri() . '/js/animations.js', array( 'gsap' ),'',true );
    
}
add_action( 'wp_enqueue_scripts', 'my_custom_scripts', 15);

add_filter('script_loader_tag','add_type_to_script', 10, 3);
function add_type_to_script($tag, $handle, $source){
    if ('custom-animations' === $handle) {
        $tag = '<script type="module" src="'. $source .'"></script>';
    } 
    return $tag;
}

First lines of "animations.js":

import * as THREE from 'https://cdn.skypack.dev/[email protected]/build/three.module.js';
import { GLTFLoader } from "https://threejs.org/examples/jsm/loaders/GLTFLoader.js";
import { DRACOLoader } from 'https://threejs.org/examples/jsm/loaders/DRACOLoader.js';

If there is other relevant code to this problem, please let me know, but I've been pouring over this and tried A) downloading the module file and putting it on my own server and providing a relative path, the same console issue appears (though it did complain with a 404 if the link was invalid, suggesting it did follow it). B) downloading the three.min.js file and loading it before this one, removing the module call entirely and I still get the same console error (even though it's not even being imported as a module). This site has been hosted on Cloudflare, so I did disable that first. Clearing the cache changed nothing, and I have confirmed at every step that I have not been loading a cached version. In the Network tab of Chrome dev tools, the module/file gets loaded into the cache just fine. Somewhere along the way, some file (I wish the console would specify, maybe that is indicative of the problem) fails to attach "Three" as a module and I have no idea why. Any help would be massively appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source