ThreeJS导入失败 - plus studio

2024-02-28 21:27:46 浏览数 (4)

问题描述

代码语言:text复制
-index.html 
-src.js
-node_modules
 -three
  -...

src.js 中用如下方式导入ThreeJS

代码语言:text复制
import * as THREE from 'three';

index.html body如下

代码语言:text复制
<body>
    <script type="module" src="/src/day01_a.js"></script>
</body>

出现报错

代码语言:text复制
Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../".

## 解决方案 stackoverflow给出了解决方案https://stackoverflow.com/questions/65697410/not-using-node-js-uncaught-typeerror-failed-to-resolve-module-specifier-thre

删除src.js的导入,将index.html body改为

代码语言:text复制
Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../".

1 人点赞