我很难理解为什么我的程序由于这个错误而崩溃:
未捕获的类型错误:无法解析模块说明符“三/示例/jsm/loaders/GLTFLoader.js”。相对引用必须以“/”、“./”或“../”开头。
我正在尝试使我的 html 文件与我创建的 serial.js 文件进行通信。 html 只是在项目文件夹中,但serial.js 文件存储在我为该项目拥有的 js 文件夹中(需要导入从 Three.js 网站下载的一些对象加载器模板。)
这是我迄今为止在 html 代码中尝试过的:
<html>
<head>
<title>Three.js Crash Course</title>
<style>
body
{
margin: 0;
}
canvas
{
width: 100%; height: 100%;
}
</style>
</head>
<body>
<script src = "js/three.js"></script>
<script src = "js/OrbitControls.js"></script>
<script type = "module" src = "./js/serial.js"></script>
</body>
</html>
我也尝试过仅使用“/js/serial”..ect 和“../js/serial.js”。为什么它无法识别并运行该文件?
I've also included an image if it's helpful for understanding the way I've set up my file structure.
您正在导入无效的 ES6 模块(如全局脚本)。我建议您使用来自例子/js https://github.com/mrdoob/three.js/tree/master/examples/js或者使用正确的模块语法。
<script async src="https://unpkg.com/[email protected] /cdn-cgi/l/email-protection/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/[email protected] /cdn-cgi/l/email-protection/build/three.module.js"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'https://unpkg.com/[email protected] /cdn-cgi/l/email-protection/examples/jsm/controls/OrbitControls.js';
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)