我正在尝试导入 Three.js。我正在遵循文档,但是我收到错误:
Uncaught TypeError: Error resolving module specifier “three”. Relative module specifiers must start with “./”, “../” or “/”
我的导入语句:
<script async src="https://unpkg.com/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1f7a6c3272707b6a737a326c7776726c5f2e312c3129" rel="noreferrer noopener nofollow">[email protected]</a>/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="26524e54434366160817151f0814" rel="noreferrer noopener nofollow">[email protected]</a>/build/three.module.js"
}
}
</script>
<script type="module">
import * as THREE from 'three';
const scene = new THREE.Scene();
</script>
我导入错了吗?我应该把“./”、“../”或“/”放在哪里?
最佳答案
我觉得您的导入映射使事情变得过于复杂,并且您引入了 very poor browser support 的风险,由 TheJim01 提出。
只需复制 https://unpkg.com/[email protected]/build/three.module.js 中的 Three.module.js 文件即可到应用程序中的本地文件夹,例如 /libraries/Three.module.js
。
然后导入它
<script type="module">
import * as THREE from './libraries/three.module.js';
const scene = new THREE.Scene();
</script>
关于javascript - 相关模块说明符必须以 “./” 、 “../” 或 “/” 开头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71941714/