Importing addons without npm

I’m working in an environment without npm. Importing THREE works as expected with the latest tag:

import * as THREE from 'https://unpkg.com/three@latest/build/three.module.js'

But importing OrbitControls is another story. this works:

import { OrbitControls } from 'https://unpkg.com/three@0.127.0/examples/jsm/controls/OrbitControls.js'

But this does not:

import { OrbitControls } from 'https://unpkg.com/three@latest/examples/jsm/controls/OrbitControls.js'

It raises the following error:

Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../".

Does anyone know why that is?

The OrbitControls.js module contains dependencies on “three”. You’ll have to tell the browser how to resolve that import (and any others). See “Install from CDN or static hosting”, under the Installation guide. This requires adding an Import Map as shown in the guide.

1 Like

I’ve now included three and all the add-ons in the project using the importmap and it works. Thanks!

1 Like