Unable to load the threejs module

I am still learning about threejs and have mostly worked on projects using a dev server (vite) locally. This setup limited me to accessing my projects only from the browser on my computer. Here is how I typically include my files in these projects:

<body>
    <script type="module" src="node_modules/three/build/three.min.js"></script>
    <script type="module" src="node_modules/three/examples/jsm/controls/OrbitControls.js"></script>
    <script type="module" src="GLTFLoader.js"></script>
    <script type="module" src="myapp.js"></script>
</body>

While this method works well with the vite server locally after running npm run dev, I wanted to serve my project on the network using a python server so it can be accessed from a different device's browser:

python -m http.server --bind 172.16.0.0 9999

Unfortunately, I encountered some issues with this approach and couldn't quite pinpoint the reason for the failure. The errors displayed in Firefox are as follows:

Loading failed for the module with source “http://172.16.0.0:9999/node_modules/three/examples/jsm/controls/OrbitControls”. 172.16.0.0:9999:12:1
Loading module from “http://172.16.0.0:9999/node_modules/three/examples/jsm/controls/OrbitControls” was blocked because of a disallowed MIME type (“text/html”).
172.16.0.0:9999
Uncaught TypeError: Error resolving module specifier “three”. Relative module specifiers must start with “./”, “../” or “/”.

In myapp.js file, this is how I import OrbitControls:

import {OrbitControls} from "./node_modules/three/examples/jsm/controls/OrbitControls"

This is the sole import statement present in myapp.js. Any assistance would be greatly appreciated. Thank you!

Answer №1

This constant error message keeps appearing repeatedly... After much trial and error, I managed to find a vanilla JavaScript method (without relying on npm installs) to include three.js for local site development. However, upon uploading it, the same issue resurfaces for all modules: The module from “mydomain.xy/three/examples/jsm/controls/OrbitControls.js” could not be loaded due to an unsupported MIME type (“text/html”)

Every attempt at integrating three.js seems to end in failure.... There is one tutorial on YouTube where the implementation is seamless and code completion works flawlessly. None of the non-npm methods seem to work except for the official website's approach. Even then, trying to separate the code into different files triggers the error once again. And frustratingly, even after upload, the problem persists. It's truly unbelievable.. This library is remarkable, but its inconsistency is disappointing.

For me, the following method worked locally (not yet tested on the server): Check out the "installation from cdn" section, it might solve your issue.. Personally, I'm not a fan of node.js, but there's one helpful video tutorial available if you prefer using nodejs/npm: https://www.youtube.com/watch?v=xJAfLdUgdc4&list=PLjcjAqAnHd1EIxV4FSZIiJZvsdrBc1Xho Following that guide, everything worked smoothly for me, including auto completion which has been rare in my experience. However, managing numerous folders for static content became tiresome over time, as I am still new to tools like parcel and webpack ^^

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

Vue 3 throws an error stating: "An uncaught DOMException occurred because the string contains an invalid character."

Exploring the capabilities of vue.js on a basic website. The setup consists of a single index.html file and all JavaScript is housed in an index.js file. The website is a work in progress, but there are no blockers preventing the JavaScript functionality ...

Retrieve outcome from successful AJAX post and update HTML using globalEval

I have a function in JQuery that asynchronously posts data function post_data_async_globalEval(post_url, post_data, globaleval) { $.ajax({ type: 'POST', url: post_url, data: post_data, dataType: 'html', async: true, ...

Rephrase the ajax call and the data retrieved

I'm struggling to find a solution for writing this code snippet without using async: false,. var imageX; var groupX; $.ajax({ type:'GET', url:'php/myphp.php', dataType:'json', async: false, success: ...

Modifying the chart width in Chart.js: A step-by-step guide

After creating a chart using Chart Js, I encountered an issue where the chart did not fit within the specified width. Adjusting the attributes of canvas proved to be ineffective, specifically with regards to the width attribute. Despite changing the value, ...

Switch out the icons within a return statement in JavaScript

Help! I have 5 empty star icons (<StarBorderIcon/>) displayed for a product on the material-ui website. I need to replace them with filled star icons (<StarIcon/>) based on the rating entered into a function. I attempted to use replace(), but i ...

Updating a behavior object array in Angular 5 by appending data to the end

After creating a service to share data across my entire application, I'm wondering if it's possible to append new data to an array within the userDataSource. Here is how the service looks: user.service userDataSource = BehaviorSubject<Array& ...

Unable to sign out user from the server side using Next.js and Supabase

Is there a way to log out a user on the server side using Supabase as the authentication provider? I initially thought that simply calling this function would work: export const getServerSideProps: GetServerSideProps = withPageAuth({ redirectTo: &apos ...

Creating a Vue.js project using npm or yarn is proving to be a challenge for me

I'm currently facing some challenges when trying to create a Vue.js project using npm or yarn. Here is the command I am using: $ vue init webpack my-project # Installing project dependencies ... # ======================== events. ...

Since updating my dependencies, I've been having trouble running the Android simulator using the command "npx react-native run-android."

Following the update of my dependencies, I am facing an issue where I am unable to build Android on the simulator using the command "npx react-native run-android". Strangely enough, the build is successful when I use Android Studio instead. ...

What is the process for creating two columns with an input box beneath them?

I am facing a challenge with my code. I am struggling to create the desired design where there are two columns and below them an input box that will be displayed when a button is pressed. The design I am aiming for can be viewed here: enter image descripti ...

Issue encountered while attempting to install Express using nodejs

Currently, I am facing issues while trying to install express using nodeJS. The errors indicate that my directories need to be renamed. Even after running npm init in the project folder, which seems to be set up correctly, I encounter problems. The command ...

What is the preferred workflow for client-side modules: (Browserify + npm + gulp) or (RequireJS + Bower + gulp)?

As I delve into various client-side Javascript modules workflows for my current Node.JS Express project, I find myself torn between Browserify + npm + gulp and RequireJS + Bower + gulp. While I lean towards CommonJS due to its syntax, the idea of sharing ...

Navigating through Objects in Angular 9

I am facing a challenge in Angular 9/Typescript while trying to iterate through the object response from my JSON data. Despite searching for solutions, I haven't found any that work for me. In my JSON, there is a section called "details" which contain ...

Firebase Firestore is returning the dreaded [object Object] rather than the expected plain object

I've created a custom hook called useDocument.js that retrieves data from a firestore collection using a specific ID. However, I'm encountering an issue where it returns [object Object] instead of a plain object. When I attempt to access the nam ...

Generating a file using buffer information in node.js

From the front-end client side, I am sending a file to the server. On the server-side, the data received looks something like this: { name: 'CV-FILIPECOSTA.pdf', data: <Buffer 25 50 44 46 2d 31 2e 35 0d 25 e2 e3 cf d3 0d 0a 31 20 30 20 6f 6 ...

Using a variable in Ajax URL with Action razor syntax

I have a function that calls a method in the controller through an Action URL. However, I need to use a parameter as the name of the method, but unfortunately, this is not possible in the current implementation. function changeDropDownList(id, dropNameToC ...

Transform the selected component in Material-UI from being a function to a class

Hello, I am currently learning about React and I have started using the select button from material-ui. The code I found on the material ui page is for a functional component, but I am more comfortable with class components. Here is the code snippet provid ...

Trigger the ontextchanged() event for an asp:TextBox using Javascript

I have a specific asp:TextBox that is structured in the following way: <asp:TextBox runat="server" AutoPostBack="True" ID="txtG1" ontextchanged="txtG1_TextChanged" onmouseout="javascript:RefreshIt(this)"/> In addition to this, there is a Javascript ...

Modifying an object's label based on a particular value using JavaScript

In my current project involving React.js charts, I am looking to organize data by month. In Django, I have set up a view to display JSON containing the total events per month in the following format: [ { "month": "2022-06-01T00:00:0 ...

JavaScript: AWS Amplify: Retrieving the User ID (Sub ID) Following User Registration. Post Registration, Not to Be Confused with Sign In

Currently, I am utilizing the authentication module from AWS Amplify. One question that has been on my mind is how to obtain the userID once a user signs up. While it is possible to retrieve the ID after a user signs in, I am specifically interested in re ...