The MarkerClusterer in Google Maps is generating an error: ERROR TypeError: Trying to assign to a constant

I am working on integrating the Google Maps Javascript API and MarkerClusterer into my Angular 6 application. However, I encountered a fatal error after compiling the application with the --prod flag. The error message I receive when trying to load map data is as follows:

ERROR TypeError: Assignment to constant variable. at C._cluster (46.47bcce1c4da198696d2d.js:1:59803) at C.load (46.47bcce1c4da198696d2d.js:1:56646) at z.calculate (46.47bcce1c4da198696d2d.js:1:62572) at markerClusterer.map.render (46.47bcce1c4da198696d2d.js:1:68639) at markerClusterer.map.addMarkers (46.47bcce1c4da198696d2d.js:1:68161)
at t.createMapMarkers (46.47bcce1c4da198696d2d.js:1:70426) at e._next (46.47bcce1c4da198696d2d.js:1:71953) at e.__tryOrUnsub (main.256af8f39dd3b7bd3744.js:1:534499) at e.next (main.256af8f39dd3b7bd3744.js:1:533644) at e._next (main.256af8f39dd3b7bd3744.js:1:532696)

When I use ng serve or ng build without the --prod flag, everything works fine. The target setting in tsconfig.json, tsconfig.app.json, and tsconfig.spec.json is es5.

The methods I'm using in the Angular component to display the map are as follows:

mapInitializer() {
    this.apiMarkers = [];
    this.coordinates = new google.maps.LatLng(this.lat, this.lng);
    this.mapOptions = {
      center: this.coordinates,
      zoom: 8,
      gestureHandling: 'cooperative',
      fullscreenControl: true,
    },
   
    this.map = new google.maps.Map(this.gmap.nativeElement, this.mapOptions);
    this.markerClusterer = new MarkerClusterer({map: this.map});
}

createMapMarkers(){            
    //clear before rendering new
    this.markerClusterer.clearMarkers();
    // reset zoom level for clusterer (integer values only)
    this.map.setZoom(8);
   
    //creating a new info window with markers info
    var infoWindow = new google.maps.InfoWindow({
      content: "",
      disableAutoPan: false,
    });
    var markers = [];
    this.data.forEach((siteInfo )=> {
    if(siteInfo.lat && siteInfo.long){
      let label = siteInfo.Address;
      let HazId = siteInfo.HazId;
      let marker = new google.maps.Marker({
        position: new google.maps.LatLng(siteInfo.lat, siteInfo.long),
        title: siteInfo.Address,
        icon: icon[siteInfo.Color], 
        ...siteInfo
      });

      //Adding marker to markers array
      markers.push(marker);
    }
  })
  
  // add markers to map
  this.setMapBounds();
  this.markerClusterer.addMarkers(markers);
}

The mapInitializer() function is called within the AfterViewInit() method, and the createMapMarkers() function is called after retrieving data from the server. If I switch the MarkerClusterer algorithm to GridAlgorithm, the error disappears; however, the default algorithm performs better.

Currently, I am using the following versions: "@googlemaps/google-maps-services-js": "3.2.5", "@googlemaps/markerclusterer": "1.0.22",

Any suggestions on resolving this error effectively would be highly appreciated.

Thank you in advance!

Answer №1

Encountered the same issue today while working on a project that is not Angular-based. In my production build configuration, the code is compressed using UglifyJsPlugin. However, disabling the unused setting resolved the issue for me:

new UglifyJsPlugin({
  uglifyOptions: {
    ecma: 5,
    compress: {
      unused: false, // <-- Make sure to set this to false
    },
  },
}),

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

Challenges arise when working with Vue 3.2 using the <script setup> tag in conjunction with TypeScript type

Hey there! I've been working with the Vue 3.2 <script setup> tag along with TypeScript. In a simple scenario, I'm aiming to display a user ID in the template. Technically, my code is functioning correctly as it shows the user ID as expect ...

Eliminate the loading screen in Ionic 2

Within my app, there is a button that triggers the opening of WhatsApp and sends a sound. Attached to this button is a method that creates an Ionic loading component when clicked. The issue I am facing lies with the "loading.dismiss()" function. I want the ...

Error encountered in lodash.js in Angular 2 framework

I have been attempting to implement lodash for a datatable. Here are the steps I followed: First, I tried running npm install lodash, but encountered an error stating that the package could not be found After researching the issue, I attempted npm in ...

Implementing Ionic Native Player for Practical Applications

Looking for a way to incorporate a lightweight mp3 file into my Ionic App, I decided to utilize Native Audio from Ionic. Despite my best efforts, the solution did not function properly on the iOS emulator when called from /MyIonicApp/src/pages/home/home.ts ...

Using a static value in the comparator is necessary for Array.find to function properly in Typescript

Looking to retrieve an item from an array: const device = this.selectedDevtype.devices.find(item => console.log(this.deviceID); return item.device_id === this.deviceID; }); console.log(device); When this.deviceID is logged, it shows "4", but t ...

Tips for troubleshooting TypeScript Express application in Visual Studio Code

Recently, I attempted to troubleshoot the TypeScript Express App located at https://github.com/schul-cloud/node-notification-service/ using Visual Studio Code. Within the launch.json file, I included the following configuration: { "name": "notifi ...

Ways to align the label at the center of an MUI Textfield

My goal is to center the label and helper text in the middle of the Textfield. I managed to achieve this by adding padding to MuiInputLabel-root, but it's not responsive on different screen sizes (the Textfield changes size and the label loses its cen ...

I'm having trouble with my Typescript file in Vscode - every time I try to edit the css code, all the text turns red. Can someone

Check out this visual representation: [1]: https://i.stack.imgur.com/9yXUJ.png Followed by the corresponding code snippet. export const GlobalStyle = createGlobalStyle` html { height: 100%; } body { background-image: url(${BGImage}); ba ...

Steps for downloading Excel or Zip files in Angular 4

Currently, my front end is built using Angular 4 and the back end is developed with Lumen 5.4. The task at hand requires me to export certain data as both an Excel and a zip file. I am utilizing the { saveAs } import from the package 'file-saver/Fil ...

Choosing the primary camera on a web application with multiple rear cameras using WebRTC

Having a bit of trouble developing a web app that can capture images from the browser's back camera. The challenge lies in identifying which camera is the main one in a multi-camera setup. The issue we're running into is that each manufacturer u ...

Encountering Main.js Path Error in Asp.net Core and Angular 2 Integration

I am currently in the process of developing an asp.net core application with Angular 2 and utilizing Angular Quickstart for assistance. With the flexibility provided by Asp.Net core application to use wwwroot as a folder, I have consolidated all dependenc ...

The deployment of my Node application on Heroku is causing an error message: node-waf is not

I've been trying to deploy my Node.js application on Heroku by linking it to my Github repository and deploying the master branch. Despite experimenting with various methods, I keep encountering the same error every time. You can view the detailed b ...

Form validation is an essential feature of the Angular2 template-driven sub form component

I'm currently working on a template-driven form that includes a group of inputs generated through an ngFor. My goal is to separate this repeating 'sub-group' into its own child component. However, I'm encountering difficulties in ensur ...

What sets aws-cdk-lib apart from @aws-cdk/core, @aws-cdk/aws-iam, and others?

There seems to be a variety of examples out there using the AWS CDK, with some referencing aws-cdk-lib and others using @aws-cdk/core. Can someone clarify the distinction between these two and provide guidance on when to use one over the other? ...

Tips for integrating CKEditor into an Angular 4 project

To start using CKEditor, I first installed it by running the command npm install ng2-ckeditor. Next, I included ckeditor.js in my index.html file. I then imported { CKEditorModule } from 'ng2-ckeditor'; in my app.module.ts file. After setup, I ...

How to bring in a module from another package in Angular 4

This is a fundamental query. As an individual just starting with Angular and npm, this may seem like a basic question for some. However, despite extensive research, I haven't been able to find a solution. Before embarking on a project, I want to cre ...

Angular click switch Component keeps track of its previous state

I recently developed an Angular component that consists of a button and an icon. One key requirement is for each instance of this component to retain its own status. For example, let's say we have three instances in the app.component.html: <app-v ...

What circumstances allow @Inject to be optional in Angular?

My Angular service is simple yet causing errors. Here's the code snippet: // service.ts export class SimpleService { // ... } // component.ts @Component({ selector: 'my-component', templateUrl: 'components/mycomp/mycomp.ht ...

The compatibility issues between Karma and Jasmine testing configurations cause errors during the Ionic packaging process

I've recently added testing to my ionic app using karma + jasmine, along with a typescript pre-processor. Below are the dependencies I have, most of which were added specifically for testing: "devDependencies": { "@ionic/app-scripts": "1.0.0", ...

Is there a kind soul out there who can shed some light on the error that pops up when I try to execute "npm run

As I embark on creating my first angular app, I started by installing it using the command npm i -g @angular/cli. However, when I attempt to create a new app with npm run ng new app, an error pops up: npm ERR! path E:\ddii\package.json npm ...