Mysterious Shadow
Mysterious Shadow

Reputation: 243

GLTFLoader gives cannot Import outside of module

With the updates to THREE.js, I have been having trouble using the GLTFLoader. It keeps giving me the error mentioned above.

Imported in a seperate js file

test.js

import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";

index.html


    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/110/three.min.js"></script>
    <script src="test.js"></script>

file structure

Upvotes: 1

Views: 332

Answers (1)

Amritesh Anand
Amritesh Anand

Reputation: 983

The import statement cannot be used in embedded scripts unless the script has a type="module".

Here is an example for the import statement with type module.

<script type="module" src="test.js"></script>

Upvotes: 1

Related Questions