An issue with the THREE.js TextureLoader not functioning properly when deployed

After implementing the code below, my project is successfully rendering my background and avatar. However, when deploying on Netlify, the rendering does not function as expected.

I have attempted using "../../", "./", and other variations, but the issue persists. Any suggestions or insights on how to resolve this?

// Background

const spaceTexture = new THREE.TextureLoader().load('./images/space.jpg');
scene.background = spaceTexture;

// Avatar

const loader = new THREE.TextureLoader().load('logo.svg'); //, color: 0x00FFEB 
const jeff = new THREE.Mesh(new THREE.BoxGeometry(2, 2, 2), new THREE.MeshStandardMaterial({ map: loader}));

scene.add(jeff);

Your help is greatly appreciated.

Answer №1

The lack of a loading manager to detect when the texture meshes are loaded while your application is live in production is causing the issue. To resolve this, you must first create a loading manager and then pass it into your texture loader. Here's an example of how to do it:

const loadingManager = new THREE.LoadingManager();

const loader =new THREE.TextureLoader(loadingManager);

const jeff =   loader.load("../assets/jeff.png");

Additionally, consider rebuilding your application using the npm parcel package to ensure it functions correctly in production on a free hosting service like vercel. Move your index.html, styles.css, and main.js files to a new source folder named src. Install parcel using npm with the following command:

npx install parcel

Also, install three.js and gsap packages, then use the following command to build:

npx parcel src/index.html

This will generate a dist folder containing a new deployable index.html. Finally, move all your image assets to the dist folder so that your dist index.html can access them

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

Remove the most recently played sound from an array of sound using Vue.js

I've been trying to figure out how to randomize the sounds that play when a button is clicked, but I also want to avoid repeating the last played sound. It just doesn't sound right if the same sound plays repeatedly in quick succession. I'm ...

`Look up values from specified key names`

Consider the following JSON data: const information = { "item1":1, "item2":20, "item3":123, "item4":[{"a":"apple","b":"ball"}], "item5":1211 } In ...

Command in Selenium Webdriver for initiating a mouse click

Currently, I am in the process of writing tests for a Java application that has been created with the Vaadin framework. To conduct these tests, I have opted to utilize the Robot Framework. In certain instances, I must implement robot framework commands suc ...

Defining global 'require' scripts in Node.js

Seeking a solution to a slightly unusual problem. I hope that using simple examples will clarify my query, as explaining my complex usage can be challenging. I am incorporating my custom modules into the routes.coffee file for an Express server. My goal i ...

Tips on preventing the occurrence of double encoding in raw JSON output from a view

I am encountering a JavaScript error while attempting to parse JSON data obtained from my controller: Uncaught SyntaxError: Unexpected token & in JSON at position 1 at JSON.parse () at stores:76 This is the code I use to serialize my list of elem ...

Notify when the focus is solely on the text box

How can I display an alert only when the focus is on a text box? Currently, I am getting an alert whenever I skip the text box or click anywhere on the page. The alert even appears when I open a new tab. Is there a way to fix this issue? Thank you for your ...

How to upload a multipart form with JSON and file using Dojo's XHR functionality

I've been struggling to find a solution for this issue. The closest I found was a thread on Stack Overflow about composing multipart/form-data with different Content-Types, but it didn't fully address my problem. Here's the situation - I ha ...

Vue watchers capturing original value prior to any updates

When working with Vue.js, we can easily access the value after modification within watchers using the following syntax: watch: function(valueAfterModification){ // ...... } But what about getting the value before it's modified? PS: The official ...

Presentation Slider (HTML, CSS, JavaScript)

Embarking on my journey of creating webpages, I am eager to replicate the Windows 10 start UI and its browser animations. However, my lack of JavaScript knowledge presents a challenge. Any help in reviewing my code for potential issues would be greatly app ...

Ensure that the submit button triggers the display of results with each click

My project involves two navigation bars, each with its own table displayed upon page load. Additionally, there is a search bar used to display search results in another table. The issue I'm encountering is that when I click the submit button once, th ...

Is there a way to continue a failed fetch request?

I am curious about the possibility of resuming an incomplete fetch request if it fails due to a non-code-related issue, like a lost network connection. In one of my current projects, we send a large download via AJAX to the client after they log in. This ...

Exploring Angular's Dependency Injection

How can I verify that a module has properly loaded its required dependencies? I've added ngAnimate to the module definition, but it doesn't appear to be functioning within the application when it runs. The environment I'm navigating is quite ...

Retrieve the JSON data based on a specific key after a specified period

Hello there, I am encountering an issue with a specific JSON key. Let's say I have an external file containing JSON data structured like this: { "key 1":[ { "linkName":"key name 1.1", "linkUrl":"key URL 1.1" }, ...

Mapping choices array in ReactJS using the id as a key reference

Looking for assistance with JavaScript as I am relatively new to it. I have a page displaying scheduled exams, and clicking on "Learn more" opens a modal where you can edit exam details. Currently, the modal displays selected equipment and allows changing ...

Sending auth0 token as a parameter in $http.get request in Angular

I am encountering difficulties when trying to attach the auth0 token to a http.get request for an API that requires the token. The token is generated upon user login and stored in the browser's local storage, which is functioning properly. The challen ...

Unable to successfully upload a .docx file within OnlyOffice utilizing JavaScript

Our application has successfully integrated the OnlyOffice editor. I am currently facing an issue while trying to upload a .docx file from my PC to the OnlyOffice server for later editing. Despite sending a POST request to the server using formdata, the fu ...

why is it that I am not achieving the expected results in certain areas of my work?

I am facing issues with getting an alert response from certain buttons in the code. The AC button, EQUALS button, and the button labeled "11" are not behaving as expected. I have tried troubleshooting but cannot identify the problem. Can someone please ass ...

Dividing a string into sections and sending each section to a function

I'm currently facing an issue while trying to pass string objects to a function. The query string in the URL contains fields that are in a comma-separated string format with attributes of interest. I've stored the attribute names in the fields a ...

Issues with CORS on PUT and POST requests in AngularJS and Node.js are preventing successful communication between the two

I'm encountering a CORS issue with my application. My tech stack consists of Node.js using Express 4 and AngularJS Despite attempting various solutions, I continue to receive the following error for all POST/PUT requests: No 'Access-Control-Al ...

Guide to displaying a loading image when selecting an item from a dropdown menu using JavaScript

When using three drop-down lists and performing an AJAX call on each dropdown list's onclick function, I encountered a delay in loading the data. To address this issue, I attempted to display a loading image while processing the AJAX call. <form ...