Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative module specifiers must start with “./”, “../” or “/”

I am trying to import three.js. I am following the documentation, however I am getting the error:

Uncaught TypeError: Error resolving module specifier “three”. Relative module specifiers must start with “./”, “../” or “/”

My import statements:

<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
<script type="importmap">
  {
    "imports": {
      "three": "https://unpkg.com/[email protected]/build/three.module.js"
    }
  }
</script>

<script type="module">

  import * as THREE from 'three';
  const scene = new THREE.Scene();

</script>

Am I importing it wrong? Where would I put the “./”, “../” or “/”?

like image 551
Ethan James Avatar asked Jan 27 '26 09:01

Ethan James


1 Answers

I feel like you're overcomplicating things with the import maps, and you're introducing the risk of very poor browser support, as brought up by TheJim01.

Just copy the three.module.js file from https://unpkg.com/[email protected]/build/three.module.js to a local folder in your app like /libraries/three.module.js.

Then import it with

<script type="module">

  import * as THREE from './libraries/three.module.js';
  const scene = new THREE.Scene();

</script>
like image 149
Marquizzo Avatar answered Jan 28 '26 23:01

Marquizzo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!