I can't figure out why I keep receiving an "Uncaught ReferenceError: THREE is not defined" message from three.js, especially after I made sure to include a requirejs shim

My code is throwing an error that says: Uncaught ReferenceError: THREE is not defined

module game {
    export class Add3DScene extends dragonwings.Command {

        @inject('ResponsiveDiv')     protected _responsiveDiv:          components.ResponsiveDiv;

        public execute(): void {
            super.execute();
            var scene = new THREE.Scene();
        }
    }
}

I am unable to implement this solution as I don't have access to the embedding html

Even though I tried this solution by adding the shim, it didn't solve the issue and I struggled with incorporating the define wrapper in my typescript.

Although I can see three.min.js loaded in chrome debugger

The use of requirejs seems to be causing complications based on my online research. Here is a simplified version of my configuration

requirejs.config({
    baseUrl: "content/${gamecode}/lib",
    paths: {
        TweenMax:           "gsap/TweenMax",
        THREE:              "three/three.min",
    },
    shim:
    {
        'THREE': {
            exports: 'THREE'
        },
        'game_libs': {
            deps: ['stats', 'TweenMax']
        },
        '../app/js/main': {
            deps: ['game_libs']
        },
    }
});

I would appreciate any help

**Edit after reading Require.js not loading Three.js my other modules are no longer defined and I have not been able to proceed with the code execution that I originally posted about new require configuration

define("three-glue", ["three"], function (three) {
    window.THREE = three;
    return three;
});
requirejs.config({
    baseUrl: "content/${gamecode}/lib",
    waitSeconds: 60,
    paths: {
        TweenMax:           "gsap/TweenMax",
        three:            "three/three.min",
    },
    map: {
        '*': {
            three: 'three-glue'
        },
    'three-glue': {
        three: 'three'
    },
    shim:
    {
        'game_libs': {
            deps: [
                'TweenMax'
            ]
        },
        '../app/js/main': {
            deps: ['game_libs']
        },
    }
}
});

Answer №1

Placing the map in different locations had different effects. When adding it after the paths but before the shims, all other modules were lost. However, placing it after the shims only caused the THREE module to be missing.

The reason for this issue was because I forgot to include 'three' as a dependency. After fixing my require config, all errors disappeared.

'../app/js/main': {
            deps: ['game_libs', 'three']
        },

Appreciate the assistance!

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

The art of transforming properties into boolean values (in-depth)

I need to convert all types to either boolean or object type CastDeep<T, K = boolean> = { [P in keyof T]: K extends K[] ? K[] : T[P] extends ReadonlyArray<K> ? ReadonlyArray<CastDeep<K>> : CastDeep<T[P]> ...

Next.js App experiences a 404 Error when attempting to access the Auth0 Endpoint "api/auth/me"

Following a tutorial, I integrated my Next.js App with Auth0 successfully. However, after logging in and out, I encountered an issue where the user object is not returned when trying to display user information on the page post-login. Both the Profile.js p ...

Steps for showcasing varied templates, such as error pages, within a single Angular X application

Is there a way in Angular 8 to switch templates within the same application? For instance, if the app consists of a container component with a header, sidebar, and footer, and the content is always displayed inside the container. What if I want to show a ...

Ensuring TypeScript recognizes a class property as definitively initialized when set using a Promise constructor

I have a simple class definition that is giving me an error in TypeScript. class Container { resolveData: (s: string) => void // not definitely initialized error! data: Promise<string> constructor() { this.data = new Promise&l ...

Fire the BehaviorSubject with the identical value following a mutation

I am working with a BehaviorSubject where I have to make changes through mutation (for reasons beyond my control). I need to trigger the BehaviorSubject for subscriptions whenever there are changes. Is there another approach I can take instead of using: ...

Troubleshooting: Resolving JSX props issue in Vue template

Ever since integrating the FullCalendar library into my Vue project, I've been encountering an error every time I try to use my custom component in a Vue template. My setup includes Vue 3, Vite, VSCode, eslint, and prettier. This issue seems to be m ...

Issue with typescript in Material-UI Next

I encountered an error while trying to integrate material-ui-next component into a default VS2017 react-redux template. The error message reads as follows: ERROR in [at-loader] ./node_modules/material-ui/BottomNavigation/BottomNavigationButton.d.ts:6:74 T ...

how to enhance Request type in Express by adding a custom attribute

In my quest to create a custom middleware function in Node.js using TypeScript, I am facing an issue where I am trying to save a decoded JSON web token into a custom request property called 'user' like so: function auth(req: Request, res: Respo ...

Typical approach to receiving a transformed object from an HTTP service

One of the services I provide includes a method with the following implementation: public fetchCrawls(page: number): Observable<ICrawl[]>{ return this._http.get(this._crawlsURL + page) .map((res: Response) => { ...

Looking for a JavaScript library to display 3D models

I am looking for a JavaScript library that can create 3D geometric shapes and display them within a div. Ideally, I would like the ability to export the shapes as jpg files or similar. Take a look at this example of a 3D cube: 3d cube ...

Using Typescript: Undefined arrays could cause issues in the array map function

Encountering a Typescript error stating that '<array name>' is possibly undefined while attempting to map over an array in Typescript. Below is an example code snippet triggering this issue: type obj = { list?: string[] }; function dem ...

I seem to be encountering an issue with my Angular 6 HTTP PUT request

Below is the code snippet: products.service: updateCategorie(ucategorie: Icategorie) { const endpoint = this.url + 'api/Category/Edit'; const headers = new Headers(); headers.append('Authorization', 'Bearer ' + localStorage ...

Unable to retrieve a method from the model class in Angular 4

I attempted to utilize a method from the model class, but encountered an error: ERROR TypeError: act.sayHi is not a function Below is my code snippet: Model Class myModelClass.ts export interface IMymodel { name: string; addres ...

Creating unique sizes for each quad in Three.js using InstancedBufferGeometry and ShaderMaterial

I'm working on creating a visually dynamic scene filled with points of varying widths and heights. The challenge I'm facing is figuring out how to manipulate the vertices in the vertex shader to achieve customized sizes for each point. Here' ...

A Guide to Catching Targeted React Notifications in Sentry using Next.js

In my Next.js application, I have implemented Sentry for error tracking. While I have successfully set up Sentry to capture errors within my try/catch blocks, I am currently struggling with capturing specific errors and warnings at a global level in my sen ...

I encountered an issue with my TypeScript function in Angular, as it is unable to process multiple uploaded files

I'm having trouble with my TypeScript function in Angular that is unable to read multiple uploaded files. fileUpload(event: Event) { const self = this; this.imageUploadInp = event.target as HTMLInputElement; this.imageUploadInp.addEventLis ...

What is the best way to showcase the information retrieved from my API?

I am attempting to display the ID and Document number that are retrieved from an array. Data Returned However, I am not seeing any results in return. You can view the application results here. I have tried using string interpolation like {{document.id}} ...

What is the best way to ensure an observable has been updated before proceeding with additional code execution?

Is an observable the best choice for providing live updates of a variable's value to another class? I have a loop in my service class that looks like this: elements.forEach(element => { doStuff(); this.numberSubject.next(valueFromDoStuff); }) ...

utilizing regular expressions to retrieve data

I am facing a challenge in extracting both the product name and price from the given data. The desired result, which includes both the product name and price, is not on the same line. How can I include the line that comes before the price as well? Here is ...

Retrieve data from a Firestore document in an Ionic application

I have a service that retrieves a specific document from Firestore using the getBidremains method. The method in the TypeScript class is called in ngOnInit like this: this.userInfo = this.firestoreService.getBidremains(userId).valueChanges().subscribe(da ...