Error encountered in THREE.js due to the specific version being imported

At the beginning of my three.js project, I opted for version 0.118.0 and included the necessary imports as shown below.

import * as THREE from 'https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a1d5c9d3c4c4e1918f9090998f91">[email protected]</a>/build/three.module.js';

import { GLTFLoader } from 'https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cebaa6bcabab8efee0fffff6e0fe">[email protected]</a>/examples/jsm/loaders/GLTFLoader.js'

Initially, using this setup posed no problems. However, when attempting to switch to a newer version like 0.148.0, I encountered a TypeError as displayed below.

Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../".

I have double-checked that the paths to the addons are adjusted based on the version used, but the issue remains unresolved. Any insights on what might be causing this problem? Thank you.

Answer №1

To ensure proper functionality of three.js addons since version r137, you must establish an import map with the following structure:

<script async src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ee8b9dc383818a9b828bc39d8687839daedfc0ddc0d8">[email protected]</a>/dist/es-module-shims.js"></script>

<script type="importmap">
  {
    "imports": {
      "three": "https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3c48544e59597c0c120d0804">[email protected]</a>/build/three.module.js",
      "three/addons/": "https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7a3bfa5b2b297f9e7e6e3ef">[email protected]</a>/examples/jsm/"
    }
  }
</script>

In your JavaScript, you can import files as follows:

import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

For more information, refer to the official Installation guide.

Regardless of environment, imports now follow a unified syntax, ensuring consistency whether importing in a node environment or directly in the browser.

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

Develop a custom function in Typescript that resolves and returns the values from multiple other functions

Is there a simple solution to my dilemma? I'm attempting to develop a function that gathers the outcomes of multiple functions into an array. TypeScript seems to be raising objections. How can I correctly modify this function? const func = (x:number, ...

Does jqgrid navgrid have an event called "on Refresh"?

Is there a way to trigger an event before the grid automatically refreshes? I am looking for something similar to "onSearch" but for the reset button. Below is the code snippet for the navgrid: $("#jqGrid").jqGrid('navGrid','#jqGridPag ...

Configuring hostname and port within next.config.js with next.js

Currently, I am utilizing next.js 9.5.x and am in search of a method to set up the hostname and port via the next.config.js file. Despite consulting the documentation, I have yet to discover a solution to this issue. Previously, I leveraged a series of .e ...

"An issue with preventing default behavior when clicking on a jQuery element

I need some assistance preventing a JQuery onclick function from scrolling the page to the top. I have tried using preventDefault() without success. You can find the code on this website: Below is the code snippet that I am currently using: $( document ...

How can Physijs enhance the realism in your Three.js projects with its physics-enabled features?

After creating a solid ground, I decided to get creative by digging a gap into it and incorporating physical effects using physijs. let Mesh = new THREE.Mesh(new THREE.BoxGeometry(800, 10, 800), material); Mesh = new ThreeBSP(Mesh); let Gap = new THREE.Me ...

What is the best way to link a JavaScript file from a node package in an HTML document?

After developing a Node.js Express App using JetBrains WebStorm, I utilized npm (via File->Settings->Node.js and NPM) to install a package called validator, specifically designed for string validation. The installation of the package went smoothly u ...

The button's background color will vanish if you click anywhere outside the button or on the body of

Struggling with a tabpane created using HTML, CSS, and JavaScript. The problem arises when the background color of the active tab's button disappears upon clicking outside the button or on the body. While switching between tabs, I can change the color ...

Transforming the value of a property in a JSON object using JavaScript

I have a JSON object that I am trying to manipulate by changing the value of its property "quantity" "[{"name":"Butter","image":"/static/images/items/dairy/butter.jpg", "price":" 30 uah","quantity":"1","alias":"butter"}, {"name":"Chesse","image":"/stat ...

What causes my Redux component to re-render when the state it's not related to changes?

My redux state structure is as follows: { entities: { cars: { byId: {}, isFetching: true }, persons: { byId: {}, isFetching: false } } } Exploring the implementation of my Person container: class PersonPag ...

What are the steps for running app.js deployed on a remote server using the local bash terminal?

After launching my web application on GoDaddy, which is built in Node.js, I have encountered a dilemma. In order to run app.js, I currently rely on my computer's bash command prompt. However, this poses an issue - if I were to shut down my laptop, the ...

Typescript error: Cannot access property "status" on type "never".ts(2339)

Currently, I have a method that utilizes nextjs/auth to sign in with credentials from a form. However, I am encountering a type checking error Object is possibly 'undefined'.ts(2532) const doStuff = async (values: any) => { const result: S ...

Confirming the information before submitting the form

My submit button is set up like this: <input class="create_button" name="commit" onclick="return validate_activity();" type="submit" value="Save"> I have noticed that this button always sends a request to the server regardless of wh ...

Improve the Popup to seamlessly elevate

In my project, I have implemented a pop-up dialog box that rises up from the left bottom corner as the user scrolls down the page. You can view it live at this link- However, I am facing an issue where the initial lift up of the dialog box is not smooth, ...

Enhancing button functionality using jQuery and JavaScript for toggling behavior

I am facing a challenge with this code. The goal is to have a single script that can handle multiple audio elements on the page and toggle between PLAY and PAUSE buttons by adding or removing classes. Can anyone suggest any changes or additions that coul ...

Enhance User Experience with JQuery Autocomplete for Internet Explorer 8 Using ASMX Web Services

Help Needed! I have been trying to implement a Web Service (ASMX) file on my website. When I access and query the page, I receive the desired results. The problem arises when I attempt to add autocomplete functionality to a textbox in my ASP.NET applicati ...

error fetching data: unable to access due to client blocking

Despite including all possible information in my request, I am still encountering the same error. How can I identify the root cause of this issue? I have already disabled my AdBlocker extension. await fetch('http://127.0.0.1:8080/hxo.json?dummy=2s21&a ...

What is the best way to assign a URL to an image source using a JavaScript variable?

I am working on a script that displays different image URLs based on the time of day using an if-else statement. I want to dynamically load these images in an img src tag so that a different picture is loaded for each time of day. I have defined variables ...

Using maxDate in Material UI DatePicker Component to set a maximum date limit

I'm having a tough time getting the maxDate property to function properly on the Material UI DatePicker component. It should disable dates after the specified maxDate. In my situation, I needed to set the maxDate to +60 days from the current Date(), ...

Leveraging promises with node.js and couched/nano for asynchronous operations

Currently experimenting with the Q promises library in conjunction with couchDB and Nano. The code below is able to display messages in the console, however, it seems that the database is not being created as expected. var nano = require('nano') ...

Provide net.socket as a parameter

What is the best way to pass the net.socket class as an argument in this scenario? Here's my code snippet: this.server = net.createServer(this.onAccept.bind(this)); this.server.listen(this.port); } Server.prototype.onAccept = function () { // Ho ...