An error occurred stating: "THREE is inaccessible when trying to import OrbitControls and OBJLoader"

After switching from using the CDN link for threejs in my html to importing threejs through npm and using webpack to compile everything, I encountered an issue. Despite no error messages during compilation, my webapp breaks with an error stating that THREE is not defined. Below are the import statements I am currently using:

import * as THREE from 'three';
import OrbitControls from 'three/examples/js/controls/OrbitControls.js'
import OBJLoader from 'three/examples/js/loaders/OBJLoader.js'

Upon inspecting the browser console, the error points me to the source code of OrbitControls, and when I commented out its import statement, the error then directed me to the source code of OBJLoader. None of my own code is causing these issues, but I can provide it if needed for debugging purposes. When removing both of those import statements and leaving only import * as THREE from 'three';, the page loads without errors, although the 3d model I'm trying to render does not appear. Any assistance would be greatly appreciated.

Answer №1

To give it a shot, include these libraries:

import { PointerLockControls } from 'three/examples/jsm/controls/PointerLockControls.js'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'

Take note that the imports are now coming from the jsm folder which stores ES6 modules.

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

Improving user input in AngularJS

My goal is to create a filter that converts time into seconds, such as: 01:30:10 becomes 5410, and vice versa. This way, the model only holds seconds while providing users with a more user-friendly representation. I've successfully implemented a work ...

Defining methods within Vue.js instances: A comprehensive guide

Hey there! I'm working on adding JSON data to an element by making a JSONP call to an external API. It seems that Vue is not recognizing the variable properly, even after following advice from the Laracasts forum about defining data and methods in com ...

What could be causing the 404 Ajax not found error in my script?

I'm facing an issue with my code. When I try to run it, I encounter the following error: 404 (Not Found) while using the get method. Here is my html code snippet. <html> <head> <title>Issue</title> <meta charset= ...

What is the best way to retrieve certain fields from a Firestore database using Next.js?

Is there a way to access a specific field in a document using the user's uid as its name? I am utilizing useAuthState from react-firebase-hooks to retrieve the user's credentials (uid). https://i.sstatic.net/t1xGL.png This code snippet allows me ...

Leveraging the power of Javascript's ajax capabilities to trigger PHP

When working with localization in JavaScript, I have encountered an issue where localization strings are stored in a php file and the get_string() function is used to retrieve the localized values in PHP. Specifically, I have created a script named alertpo ...

Show the contents of a JSON file using Vue

I have a JSON file containing some data that needs to be fetched and displayed in a component. In the actions of my Vuex store, I've implemented: async getTodos (context) { const todos = [] const response = await fetch('../../data/todos.jso ...

Is there a way to calculate the total sum from another table using Sequelize or SQL?

I currently have three interconnected models: Workout Circuit CircuitStep Each Circuit has a repeatCount that determines how many times it is repeated, and each CircuitStep has a duration. My query is: How can I instruct the Workout model to calcul ...

The issue of numbers not being properly summed in Node.js

I'm currently working on storing product prices in sessions. The issue arises when a product is clicked twice - instead of adding the two prices together, they concatenate into a single value. For example, 15 + 15 results in 01515. I'm unsure why ...

Managing switch input in Node.js: A comprehensive guide

Feeling completely lost while attempting to gather input from a switch using Express. I'm aiming to create a real-time application where toggling the switch triggers a response on the server side. Utilizing Bootstrap, here's a snippet of the HTML ...

Unpredictable preset inline styles for HTML input elements

While developing a full-stack MERN application, I encountered an unusual issue when inspecting my React UI in Chrome DevTools. If any of these dependencies are playing a role, below are the ones installed that might be contributing to this problem: Tail ...

Is there a comparable route to res.locals in Express.js?

Using Express.js/Jade allows for the addition of a function or variable to res.locals, which can then be utilized in a Jade view as shown below. Within Express middleware: res.locals.myUtilFunction = function(){ return 'Hello' }; In Jade: - c ...

Is the order of state variables important in React components?

Upon executing the code below, an error "Cannot read properties of null (reading 'login')" occurs, triggered by reaching the return statement at the end. This error persists despite the presence of checks for the boolean before the return stateme ...

What is the best method for iterating through JSON data and extracting a specific key-value pair?

Having just started learning JavaScript, I'm a bit confused on how to retrieve a specific key value from a JSON file: var me = {"fcolors": ["blue", "green", "whitesmoke"],"fire": ["pink", "grey", "red"]}; I am interested in extracting only the fcolo ...

Elements recognized worldwide, Typescript, and a glitch specific to Safari?

Consider a scenario where you have a select element structured like this: <select id="Stooge" name="Stooge"> <option value="0">Moe</option> <option value="1">Larry</option> <option value="2">Curly</option ...

The Content-Type header is missing in the Ajax request for json

In my PHP code, I generate valid JSON and set the content-type header to application/json in my development environment. However, when I deploy this code to an embedded web server, it functions properly but is unable to send the appropriate content-type he ...

What is the best way to integrate a notification system using jQuery?

I am looking to create a notification area that will refresh whenever a new message is sent using jQuery or Ajax (my database is stored in a soap server). I want to make a soap call every few seconds to achieve this, but I'm not sure how to go about i ...

Error encountered when attempting to insert data into database due to incompatible data types

I am experiencing an issue with Vue multiselect. I am trying to save the id of selected options in a database, but it seems that I am encountering an error related to Array to string conversion. I have declared both site_id and administrator in fillables. ...

Strange behavior observed when making HTTP requests while updating views during load method

I have an AngularJS application with multiple views. One of these views controls a tool that can be in three different states: started, stopped, or paused, each corresponding to a different button. The tool is located on a server, and I want the view to u ...

What is the method for extracting a list of properties from an array of objects, excluding any items that contain a particular value?

I have an array of objects, and I want to retrieve a list with a specific property from those objects. However, the values in the list should only include objects that have another property set to a certain value. To clarify, consider the following example ...

How can we integrate this icon/font plugin in CSS/JavaScript?

Check out the live demonstration on Jsfiddle http://jsfiddle.net/hc046u9u/ <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materializ ...