I’ve had an game working on Facebook Instants for a year or so and I’ve come back to update it.
I used to just include the tag:
<script src="js/Three/three.js"></script>
In my index.html and all my three app code would work fine.
I’ve updated to the latest version of three (effectively deleted my old three srouce tree and copied the most recent version in there) and all my references to THREE. throw a
ReferenceError: THREE is not defined error.
I’ve noticed my old version of three.js used to have a load of code in, whereas the new version seems to have a bunch of exports instead and no code.
Can anyone tell me what I need to do to get it back working again? I’ve look at the examples and they seem to do some import logic that I’m not familiar with, all contained withing a script of type ‘module’.
I guess three.js isn’t backwards compatible with my old code?
It seems you get the runtime error because you are creating an instance of THREE.OrbitControls without including the respective script. Note that THREE.OrbitControls is no part of the core but the examples directory. I’ve updated your code here:
Has anyone encountered this issue again since? I’ve followed trough by changing three.js to the UMD version but to no avail, I get the same error:
Uncaught ReferenceError: THREE is not defined
at (index):12
this is the code I’m running, I’ve also tried putting a Alert() tag in the beginning of the three.js file to check if it was being loaded and got nothing in return, but other .js test files with alerts I placed on the same folder returned results.
for starters, your script tag on line 9 is written funny.
double check it. In your image it says scr= instead of src=
alter your line 9 to be <script src="js/three.js"></script>
i have the same error, it is like i load a thee.js file and than execute the other script. but instead the other script executes even before threejs file is loaded, and the disturbing part is it happens randomly, sometimes the code works properly and sometimes they show up this not defined error
I don’t get it. So is it not possible to use the official version of threejs, to include the 3js code in an external file? It just strikes me as so odd if the correct way to install threejs, is something completely different than what’s on the website itself. Will this, slightly modified version of 3js come back to haunt me later?
And when I do use this other version, I get error “Three.Scene is not a constructor”.
I am having the same question as the author here. But apparently not with the same answer.
Of course you can do this. The user @Dhruv_Vagadiya just imports the ESM version of three.js in the wrong way.
Everything should be explained in the Installation guide. So you need an import map and then include the import * as THREE from 'three'; statement in your main script file. The import map is needed so the browser knows how to resolve the three bare module specifier.
I’ve checked your code in your other post. You need type=“module” in your script tag when working with ESM.
So ESM is just EcmaScript Modules, and Ecma is just Javascript so it’s Javascript Modules.
I’ve been programming with Javascript modules for 15 years now.
But there are loops in my knowledge. Clearly. Always getting better.