Skip to content
Advertisement

Failed to resolve module specifier “three”. Relative references must start with either “/”, “./”, or “../”

I am currently trying to load a .obj model into my three.js project. I feel like I have all the code correct becasuse my code compiles without any errors, but when I go to Google Chrome’s console it is giving me this error. enter image description here.

mainpage.html

[![enter image description here](https://i.stack.imgur.com/cVOeN.png)](https://i.stack.imgur.com/cVOeN.png)

mainpage.js

enter image description here

Advertisement

Answer

Try changing:

<body>

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

</body>

To ->

<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>

Basically, you’re adding an Import Map. I’m not sure however if this code that I just typed, will fix your problem since you just sent screenshots of the code, instead of the actual code. For this reason, i’ll be linking you a website that explains more about Import Maps and once again the link that @Rabbid76 commented, please also take a look at that one.

ImportMaps

Please read this one

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement