There is a wired bug where if you use the example/jsm
modules as a standalone with/without three.module.js
it shows this error:
TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../".
at /
At first, I thought it was my code but after some testing and looking around, I found this as the possible culprit.
import {
EventDispatcher,
Quaternion,
Vector3
} from 'three';
I think what is happening is that the import statement tries to get the “three” module when it does not exist even though the module.js
does.
I try to fix this by changing the import statement to reference three.module.js
and it works!
modules/FlyControls.js
import {
EventDispatcher,
Quaternion,
Vector3
} from './three.module.js';
script.js
import { FlyControls } from "../modules/FlyControls.js"
console.log(FlyControls)
output / console
Function {}
I’m not sure how to fix this for the library as a whole as I’m a BIG NOOB when it comes to modules and I consider myself okay at javascript.
Here are the MREs:
- Three import bug - JSFiddle - Code Playground (Does not seem to work)
- https://replit.com/@ErrorbotTHE2nd/3js-Bug (shows error)
Finally, my live code: