Whilst attempting to import my very first .gltf
model into three.js using the Parcel bundler, I encountered a black screen and the following error message:
SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
at JSON.parse (<anonymous>)
at GLTFLoader.parse (GLTFLoader.js:315:21)
at Object.onLoad (GLTFLoader.js:205:11)
at three.module.js:39951:38
Here are my imports:
import * as THREE from 'three';
import { PerspectiveCamera } from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js'
let loader = new GLTFLoader();
loader.load( './js/assets/brain.gltf', function ( gltf )
{
brain = gltf.scene;
brain.scale.set(2, 2, 2);
brain.position.y = 4;
scene.add(brain);
} );
HTML:
<script async src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="096c7a2464666d7c656c247a6160647a4938273a273f">[email protected]</a>/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "../build/three.module.js",
"three/addons/": "./jsm/"
}
}
</script>
<script type="module" src="./js/index.js" defer></script>
</body>
Are my asset paths correct? Take a look at my path.
I have experimented with various GLTF files, tested using GLB files, and even made changes to my file paths, but unfortunately, I keep encountering the same error.