回到一些旧项目,我发现什么都没有加载。检查控制台日志,我看到以下内容:
Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../".
在我的脚本中,我得到以下内容:
<script type="module">
import * as THREE from "https://cdn.skypack.dev/three/build/three.module.js"
import { OBJLoader } from "https://cdn.skypack.dev/three/examples/jsm/loaders/OBJLoader.js"
import { FirstPersonControls } from "https://cdn.skypack.dev/three/examples/jsm/controls/FirstPersonControls.js"
我尝试退后一些版本,直到我达到0.136.0
这个错误才消失。一个导入的方式是否发生了three.js
变化,或者这是一个错误?
另外,是否有某种方法可以在运行时捕获它?就像我从 Skypack 获得最新版本号并尝试导入一样。如果失败,自动退回小数并重试。
使用 .编辑
@Mugen87 优惠importmap
。我用以下内容更改了我的代码:
<script type="importmap">
{
"imports": {
"three": "https://cdn.skypack.dev/three/build/three.module.js",
"three/OBJLoader": "https://cdn.skypack.dev/three/examples/jsm/loaders/OBJLoader.js",
"three/FirstPersonControls": "https://cdn.skypack.dev/three/examples/jsm/controls/FirstPersonControls.js"
}
}
</script>
<script type="module">
import * as THREE from "three"
import { OBJLoader } from "three/OBJLoader"
import { FirstPersonControls } from "three/FirstPersonControls"
我收到以下错误:
Uncaught SyntaxError: The requested module '/-/three@v0.137.5-HJEdoVYPhjkiJWkt6XIa/dist=es2019,mode=raw/build/three.module.js' does not provide an export named 'default'