【问题标题】:Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../"无法解析模块说明符“三”。相对引用必须以 \"/\"、\"./\" 或 \"../\" 开头
【发布时间】:2022-11-16 13:43:12
【问题描述】:

我目前正在尝试将 .obj 模型加载到我的 three.js 项目中。我觉得我的所有代码都是正确的,因为我的代码编译没有任何错误,但是当我转到 Google Chrome 的控制台时,它给了我这个错误。 。

主页.html

主页.js

【问题讨论】:

标签: javascript html three.js


【解决方案1】:

尝试改变:

<body>

  <script src = "../node_modules/three/build/three.js"></script> 
    <script type = "module" src = "../public/mainpage.js"></script>

</body>

至 ->

<body>

  <script src = "../node_modules/three/build/three.js"></script> 

    <script type="importmap">
            {
                "imports": {
                    "three": "../build/three.module.js",
                    "three/addons/": "./jsm/"
                }
            }
        </script>

    <script type = "module" src = "../public/mainpage.js"></script>

</body>

基本上,您要添加一个导入地图。 但是我不确定我刚刚输入的这段代码是否能解决您的问题,因为您只是发送了代码的屏幕截图,而不是实际代码。 出于这个原因,我将为您链接一个网站,该网站解释了更多关于导入地图的信息,并再次链接了 @Rabbid76 评论的链接,请也看看那个。

ImportMaps

Please read this one

【讨论】:

  • 这有效!非常感谢您的帮助。你是一个传奇!我必须确保路径正确。
【解决方案2】:

根据我的理解

<script type="importmap">
        {
            "imports": {
                "three": "../build/three.module.js",
                "three/addons/": "./jsm/"
            }
        }
    </script>

“三”是我编造的词。它可以是任何东西,但我强烈建议您选择明智的词来提高代码的可读性。将某些内容导入 JS 文件时,必须使用该词。

“../build/three.module.js”是在我的例子中“三”所在的路径。

如果我错了,请告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多