You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

导入THREE.js及GLTFLoader失败求助:模块解析错误

THREE.js 和 GLTFLoader 导入失败求助

尝试导入THREE.js文件和GLTFLoader但无法正常运行,已自行搜索未找到合适解决方案,特此求助。

相关代码

HTML代码

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

JS代码

import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.151.3/three.min.js';
import { GLTFLoader } from "https://cdn.jsdelivr.net/npm/three@0.151.3/examples/jsm/loaders/GLTFLoader.js";
var scene, camera, renderer, model;

init();
function init() {
  scene = new THREE.Scene();

  camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
  camera.position.z = 5;

  renderer = new THREE.WebGLRenderer({ antialias: true });
  renderer.setSize(window.innerWidth, window.innerHeight);
  document.body.appendChild(renderer.domElement);

  const loader = new THREE.GLTFLoader();
  loader.load('img/futuristicface.glb', function (gltf) {
    model = gltf.scene;
    scene.add(model);
  });
  animate();
}
function animate() {
  requestAnimationFrame(animate);
  renderer.render(scene, camera);
}

错误信息

Uncaught TypeError: 无法解析模块标识符"three"。相对引用必须以"/"、"./"或"../"开头。


内容的提问来源于stack exchange,提问作者dnos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 15:22:25