【发布时间】:2021-04-25 16:10:00
【问题描述】:
通常不是 JS 程序员。我建立了一个新的WebStorm项目,使用npm安装了three.js,一切看起来都很好,但是当我尝试导入它时,导入语句很好,但是你不能使用它,没有代码完成。
显然我错过了一些重要的事情。三个在package.json 中正确显示并锁定json,我在通常的node_modules 中拥有所有文件。任何使用 import THREE 都不会显示任何内容。没有错误,只是关于未使用项目的警告,WebGLRenderer 未定义。
这是 ECMAScript 6 的默认 WebStorm 设置。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My first three.js app</title>
<style>
body { margin: 0; }
</style>
</head>
<body>
<script type="module">
import * as THREE from 'three';
function main()
{
const canvas = document.querySelector('#c');
const renderer = new THREE.WebGLRenderer({canvas});
}
</script>
<canvas id="c"></canvas>
</body>
</html>
【问题讨论】: