首页 > 解决方案 > GLTFLoader 无法导入模块外

问题描述

随着对 THREE.js 的更新,我在使用 GLTFLoader 时遇到了问题。它不断给我上面提到的错误。

在单独的 js 文件中导入

测试.js

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

索引.html


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

文件结构

标签: htmlthree.js

解决方案


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>

推荐阅读