Encountering an unexpected token error while building an Angular4 --prod project that involves Three

Encountering an error while trying to build an Angular4 project in production with the following command:

node --max_old_space_size=8192 'node_modules/@angular/cli/bin/ng' build --prod --output-hashing=al

Error:

ERROR in vendor.422622daea37e6baf83f.bundle.js from UglifyJs Unexpected token: name (BoxGeometry) [vendor.422622daea37e6baf83f.bundle.js:84218,6]

Using the -sm flag provides more detail:

ERROR in vendor.422622daea37e6baf83f.bundle.js from UglifyJs Unexpected token: name (BoxGeometry)
[MYAPPPATH/node_modules/three/build/three.module.js:12832,0]
[vendor.422622daea37e6baf83f.bundle.js:84218,6]

The line causing the issue in three.module.js:12832 is:

class BoxGeometry extends Geometry {

...followed by a small class definition.

Building without the --prod flag works as expected, just like using ng serve.

The problem may be due to ES6 code in the ThreeJS plugin JS not being transpiled to ES5. I attempted adding "allowJs": true, to tsconfig.json which removed the error, but led to duplicate identifier errors in the tether plugin instead. It seems this is not the ideal solution anyway.

Playing around with the TS target version in tsconfig eliminates the error but introduces other errors.

There are no import statements in app.module.ts. Instead, I am importing into the component that contains the ThreeJS code using:

import * as THREE from 'three';

Here is the content of package.json:

{
  "name": "main-app",
  "version": "0.0.0",
  ...

Reviewing the webpack entry in package-lock.json:

"webpack": {
      ...

Check out my tsconfig.json configuration:

{
  "compileOnSave": false,
  ...

What should be my next course of action?

Answer №1

After some trial and error, I managed to solve the issue by eliminating three mode modules and opting for the precompiled version of three.js from github. Adding a reference to it in the angular-cli.json file alongside other dependent scripts enabled three.js to function seamlessly:

Snippet from angular-cli.json:

...
"scripts": [
        ...
        "assets/libs/three/three.min.js",
        "assets/libs/three/GLTFLoader.js",
        "assets/libs/three/DragControls.js"
      ],
...

Additionally, you must include this declaration at the start of your component:

declare const THREE: any; // add an ambient declaration

While this solution successfully addresses the issue, unfortunately, I no longer have access to my previous three typings, making it less than ideal.

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

Why are UI changes delayed when using Angular2 Google Maps events?

I am working on an Angular2 application that integrates the Google Maps JS API. When loading Google Maps, I include the script like this: <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script> To listen to events on ...

Creating an Image Slideshow on Your Website

I'm looking to create an image slideshow on my website that functions similarly to the one found at . However, I want the images to occupy the entire screen rather than having smaller images like the reference site. Can anyone offer guidance on how t ...

The Gulpfile.js encountered an error while trying to load

My Visual Studio task runner is having trouble loading the gulp file. I am currently using VS2017 v15.9.4, but the project was developed some years ago. Failed to run "...\Gulpfile.js"... cmd.exe /c gulp --tasks-simple assert.js:350 throw err; ...

Tips for implementing JS function in Angular for a Collapsible Sidebar in your component.ts file

I am attempting to collapse a pre-existing Sidebar within an Angular project. The Sidebar is currently set up in the app.component.html file, but I want to transform it into its own component. My goal is to incorporate the following JS function into the s ...

Updating Text within a Label with jQuery

Seeking assistance with a jQuery issue that I am struggling to resolve due to my limited experience. Despite attempting to search for solutions online, I have been unable to find an alternative function or determine if I am implementing the current one inc ...

When utilizing destructuring in React.js with TypeScript, incorrect prop values are not being alerted as expected

I recently started using TypeScript and I have been enjoying it so far. However, I came across an issue today that I couldn't solve. Imagine a scenario where a parent component A passes a function that expects a numeric value to the child component B ...

Uploading videos on Mobile Safari causes the website to refresh automatically

Setting up a photo uploading server on a raspberry pi using Angular with Node.Js and multer has been an exciting project for me. I opted to host it on an unsecured ad-hoc network created by the pi itself so I can easily take it on road trips and store phot ...

Is there a method to delay HTTP requests until the number of pending requests drops below a certain threshold (N)?

I'm in the midst of a project that involves allowing users to upload multiple files simultaneously. However, sending out numerous requests all at once can overwhelm the server and trigger a 429 (Too Many Requests) error for those requests. Is there a ...

Tips for dynamically coloring table cells in Spotfire based on their values

Creating Dynamic Table with HTML After successfully creating a cross table in Spotfire, I now aim to replicate the same table in HTML within a text area. I managed to add values using calculated values, but I'm stuck on how to dynamically set the bac ...

I have a desire to use Javascript to control CSS styles

Within the CSS code below, I am seeking to vary the size of a square randomly. This can be achieved using the Math.random() property in Javascript, but I am uncertain how to apply it to define the size in CSS. #square { width: 100px; height: ...

What is causing the continuous appearance of null in the console log?

As part of my JavaScript code, I am creating an input element that will be inserted into a div with the id "scripts" in the HTML. Initially, I add a value to this input field using JavaScript, and later I try to retrieve this value in another JavaScript fu ...

Increase numbers with uniform speed using jQuery for each number

I am working on implementing a jQuery script that will visually increase any number from zero to its value using setInterval(). Here is the current solution I have come up with: $('.grow').each(function() { var $el = $(this); va ...

In the world of Knockout JS, forget about using e.stopPropagation() because it won't

In my table, I have two actions that can be performed: Click event on the row level and click while checking a checkbox inside that row. However, when the checkbox is checked, I do not want the click event on the row to be triggered. <tbody data-bin ...

Tips on how to modify a select option in vue based on the value selected in another select

My Web Api has methods that load the first select and then dynamically load the options for the second select, with a parameter passed from the first selection. The URL structure for the second select is as follows: http://localhost:58209/api/Tecnico/Tanq ...

I'm having trouble utilizing toastify.js after installing it via npm. I keep receiving the error message "Failed to resolve module specifier." Any advice

Currently, I am attempting to utilize Toastify-js, a library designed for toast type messages, by installing it through npm. In the provided documentation, following the execution of the installation command, there is a direction that states: - To begin ...

ControlValueAccessor failing to populate with data from external service

After realizing the previous question was slightly off track, I am focusing on creating a custom component that can be bound to a FormControl within a FormGroup. I have successfully made it work for user input using CVA, but facing issues when preloading ...

The data-ng-bind directive cannot be used with the <option> tag

Currently, I am in the process of learning angular and encountered a problem that has me stuck. Upon researching on AngularJS : Why ng-bind is better than {{}} in angular?, I found out that both {{}} and ng-bind are said to produce the same result. However ...

The variable isJoi has been set to true but there is an error due to an unexpected

I am currently developing a NestJs backend on multiple machines. One of the machines is experiencing issues with the @hapi/joi package. When running the NestJs application in development mode on this specific machine, I encounter the following error: PS C ...

`The logo does not dim when the popup is displayed`

I'm currently experiencing an issue with pop-ups on my page - when they appear, they create a shade over all elements of the page except for my two logos and are displayed with a border around them. Here's what my page looks like before the popu ...

A guide on integrating a submission button that combines values from multiple dropdown forms and redirects to a specific URL

Is there a way to make the submit button on this form act based on the combined values of two different dropdown menus? For instance, if "west" is selected from the first dropdown and "winter" is selected from the second dropdown, I want it to navigate to ...