When attempting to implement orbit controls with Three.js, an error occurred stating "GET http://127.0.0.1:3000/build/three.module.js net::ERR_ABORTED 404 (Not Found)"

In my attempt to construct a Sky Box using three.js, I successfully created the cube and applied textures. However, I am now faced with the task of incorporating camera controls. After creating the OrbitControls.js file and implementing the necessary code, I encountered an error when trying to utilize

let controls = new OrbitControls( camera, renderer.domElement );
. The error message displayed was
GET http://127.0.0.1:3000/build/three.module.js net::ERR_ABORTED 404 (Not Found)
while attempting to integrate orbit controls with three.js. Despite adding a three.module.js file and including its code in my HTML using
<script type="module" src="three.module.js"></script>
, the issue persisted.

Below is my JS code along with the script tags that import three.js:

<body>
        <script src="three.js"></script>
    <script type="module" src="three.module.js"></script>
        <script type="module">
    import { OrbitControls } from "./OrbitControls.js"
    const scene = new THREE.Scene();
    const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
    const renderer = new THREE.WebGLRenderer();

    renderer.setSize( window.innerWidth, window.innerHeight );
    document.body.appendChild( renderer.domElement );
    const geometry = new THREE.BoxGeometry();
    const material = []
      let texture_ft = new THREE.TextureLoader().load("cocoa_ft.jpg");
      let texture_bk = new THREE.TextureLoader().load("cocoa_bk.jpg");
      let texture_up = new THREE.TextureLoader().load("cocoa_up.jpg");
      let texture_dn = new THREE.TextureLoader().load("cocoa_dn.jpg");
      let texture_rt = new THREE.TextureLoader().load("cocoa_rt.jpg");
      let texture_lf = new THREE.TextureLoader().load("cocoa_lf.jpg");

      material.push(new THREE.MeshBasicMaterial( { map: texture_ft }));
      material.push(new THREE.MeshBasicMaterial( { map: texture_bk }));
      material.push(new THREE.MeshBasicMaterial( { map: texture_up }));
      material.push(new THREE.MeshBasicMaterial( { map: texture_dn }));
      material.push(new THREE.MeshBasicMaterial( { map: texture_rt }));
      material.push(new THREE.MeshBasicMaterial( { map: texture_lf }));
    const cube = new THREE.Mesh( geometry, material );
    scene.add( cube );

    camera.position.z = 5;

    function animate() {
      requestAnimationFrame( animate );
      renderer.render( scene, camera );
    }
    
    animate();

    let controls = new OrbitControls( camera, renderer.domElement );
        
    </script>
    </body>

Answer №1

The issue you are experiencing is likely related to the file directory setup. By using src="three.module.js" in your HTML file, you are indicating to the browser that both your .html and three.module.js files are located in the same directory. To resolve this, you may need to adjust the src attribute to correctly point to the location of the JavaScript file:

  • src="../three.module.js"
    - moves up one folder level
  • src="./subfolder/three.module.js"
    - navigates into a subfolder

Review your folder structure and ensure that you are pointing to the correct location. The same applies for OrbitControls as well.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with React occurring when attempting to delete an input component

I seem to be facing a challenge that I can't quite figure out whether it's related to React or not. To help illustrate the issue, I've created a simple example outside of my project: https://codepen.io/as3script/pen/VMbNdz?editors=1111 Wit ...

What is the method for formatting within the <textarea> element?

While working on developing a comment system, I recently made the discovery that text areas cannot be formatted to retain paragraphs, line breaks, etc. This was particularly noticeable when comparing sites like StackOverflow, which uses a text editor inste ...

Increase the div id using jQuery

I've got this code snippet here and, oh boy, am I a newbie. How can I increase the number in the div using a jQuery script? if($res >= 1){ $i=1; while($row = mysqli_fetch_array($qry)){ echo "<div clas ...

Issue with inconsistent error handling in Mui DateTimePicker and react-hook-form

I am currently facing an issue with a DateTimePicker component that I am trying to integrate into a form controlled by react-hook-form. The validation is straightforward - I am using the disablePast prop on the DateTimePicker to ensure that the selected da ...

Eliminating the data type from the array of JSON entities

In my Node.js project, I have defined a class as follows: let id; let totalCalls; let totalMinutes; class CallVolume { constructor(id){ this.id = id; this.totalCalls = 0; this.totalMinutes = 0; } } module.exports = CallVolume ...

Automating the process of transferring passwords from Chrome Password Manager to a Chrome Extension

Embarking on my first chrome extension journey, I have been developing a password manager app that offers enhanced functionalities beyond the default chrome password manager. A recent request from a client has come in, asking me to gather all passwords fr ...

Creating customized JavaScript using jQuery for Drupal 7 Form API

Currently, I am working on developing a custom form using Drupal 7 with form API and a tableselect that includes checkboxes. I have some specific constraints for selecting the checkboxes that I intend to implement using jQuery. I created a function for han ...

Traversing through pair of arrays simultaneously using forEach loop in JavaScript

I am trying to create a for loop that simultaneously iterates through two variables. One is an array named n, and the other, j, ranges from 0 to 16. var n = [1,2,3,5,7,8,9,11,12,13,14,16,17,18,20,21,22]; var m = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; ...

Exploring Entries in Several JSON Arrays

In my current project, I have successfully generated JSON using JSON-Simple. Query: I am seeking guidance on how to extract specific elements like "Sentiment," "score," and "review" from this JSON array. Although I have referred to a helpful resource he ...

Integrate a resizable sidebar on the webpage's right side that dynamically adjusts the layout

As I develop a Chrome Extension, my goal is to incorporate a sidebar into all webpages without overlapping the existing content. The sidebar should be placed beside the content, effectively reducing the width of the body of the webpage to the initial width ...

Is there a way to use HTML and CSS to switch the style of a dynamic decimal number to either Roman numerals or Katakana characters within a specified HTML element, such as a tag, div

I've searched everywhere but only found guides on list styling and counter styling in CSS that didn't work out. So, for example, I have a number inside an HTML tag that is changed dynamically using Vue Watch. I want to display the number in upper ...

Refreshing a webpage with JavaScript directly from the server (2021)

Utilizing Javascript, I have successfully implemented a cookie setting feature that allows users to switch between normal and classic theme versions on my website by clicking a checkbox. The backend of my application is powered by PHP. My goal is to access ...

Check for non-null Sequelize Where conditions

Suppose I need to execute a select command using Sequelize with the condition: WHERE ID=2134 However, if the user does not provide an ID, then the WHERE clause should be omitted (as it is null). What is the best way to handle this situation in Sequelize ...

In order of service - avoid repeating the initial service upon the next user click if the second service was unsuccessful

Seeking assistance. I am new to Angular + RxJS, so please bear with me if this task seems easy. The concept is to submit a form that includes multiple input fields, one of which is for uploading an image. When the user clicks the submit button, the first ...

Prevent the function from being triggered repeatedly while scrolling

When a user scrolls to the bottom of the page, the following code is meant to load the next page. However, there are instances where it repeats itself due to rapid scrolling or while the AJAX content is still loading. Is there a way to prevent this code f ...

Is there a way to trigger a JavaScript function once AJAX finishes loading content?

I've been utilizing some code for implementing infinite scrolling on a Tumblr blog through AJAX, and it's been performing well except for the loading of specific Flash content. The script for the infinite scroll can be found here. To address the ...

Having trouble with VueJS Router-link not redirecting to the correct view?

I am facing an issue with the router link. When I use it in a view, it works perfectly fine as I have a clickable link. However, when I include a router link in a component nested within a view, the router link stops working - all I want is to link to the ...

Attempting to gather data from an HTML form and perform calculations on it using JavaScript

Looking for help with extracting user input from HTML and performing mathematical operations in JavaScript. Coming from a Python background, the variable system in JavaScript is confusing to me. Can someone provide guidance on how to achieve this? <div ...

Is it possible to utilize the AmMap API for developing an Android application?

I am currently in the process of creating a unique application with HTML, JS, and jQuery Mobile that will feature interactive maps. I have been searching the web for APIs to incorporate interactive maps into my project without using Google Maps APIs when I ...

Dispatch is functioning properly, however the state remains unchanged

I'm currently developing an application that utilizes redux for state management. In a particular scenario, I need to update the state. Here is how my initial state and reducer function are set up: import { createSlice } from '@reduxjs/toolkit&a ...