Hello everyone,
I’m encountering the following error when trying to run my Three.js project locally using a Python HTTP server:
Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../".
Here is a simplified version of my setup:
- I import Three.js and its examples modules directly from the CDN in my
main.jsfile, which is loaded as a module in my HTML:
import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.154.0/build/three.module.js';
import { GLTFLoader } from 'https://cdn.jsdelivr.net/npm/three@0.154.0/examples/jsm/loaders/GLTFLoader.js';
import { OrbitControls } from 'https://cdn.jsdelivr.net/npm/three@0.154.0/examples/jsm/controls/OrbitControls.js';
- My HTML includes:
<script type="module" src="main.js"></script>
- I run a local server using:
python -m http.server 8000
- I open the page at
http://localhost:8000.
I verified that main.js is loaded properly (I added a console.log at the start). The error appears to come from somewhere inside the modules or a related import, but I only have this one JS file.
I suspect there might be a module import somewhere referencing "three" without a relative or absolute path, but I can’t find it.
Could someone help me identify what could cause this error in this setup? Any ideas or debugging tips would be greatly appreciated!
FULL CODE : https://codepen.io/Nathan-Loheac/pen/ZYbQMqO
Thanks in advance.