【问题标题】:Using Three.js with WebStorm, module import not working将 Three.js 与 WebStorm 一起使用,模块导入不起作用
【发布时间】: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>

【问题讨论】:

    标签: three.js webstorm


    【解决方案1】:

    重新启动 Webstorm 使其再次工作。该应用程序运行了几周,因此可能存在内存泄漏或其他问题。

    【讨论】:

      猜你喜欢
      • 2020-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-15
      • 2014-07-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多