I am completely new to javascript and unfamiliar with working with libraries. I am currently experimenting with basic three.js code, but unfortunately facing issues that I cannot seem to resolve. Following the documentation on Threejs.org, I have set up a simple scene and am attempting to add orbit controls. However, everything seems to be working fine until I try to import the orbit controls into my main script file, which results in an error message:
Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../".
Unfortunately, due to my limited experience, I haven't been able to make much progress in solving this issue yet. I have double-checked for any typos and made sure that the relative paths for my imports are correct.
Below is the snippet of code that is currently functioning:
import * as THREE from '/node_modules/three/build/three.module.js';
// import { OrbitControls } from '/node_modules/three/examples/jsm/controls/OrbitControls.js';
// Construct basic scene elements
const camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
1,
1000
);
const renderer = new THREE.WebGLRenderer();
const scene = new THREE.Scene();
// const controls = new OrbitControls(camera, renderer.domElement);
// Set parameters for scene elements
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
As soon as I uncomment the second import statement for the orbit controls, it breaks and shows the error mentioned earlier. Could someone please help me understand what is causing this error and guide me on how to fix it?
Thank you in advance.