leaflet plugin markerClusterGroup does not work in Angular 19 Build

Discussão em 'Angular' iniciado por Enzo Bondan, Junho 3, 2025.

  1. Enzo Bondan

    Enzo Bondan Guest

    I'm testing my angular project on docker to try the build, and everytime I access the page related to the map I recieve this error on log: "TypeError: yt.markerClusterGroup is not a function"

    These are the imports from mapa.component.ts:

    import { Component, Inject, PLATFORM_ID, OnDestroy, OnInit } from '@angular/core';
    import { MapaServiceService } from '../../services/mapa-service/mapa-service.service';
    import { Subscription } from 'rxjs';
    import * as L from 'leaflet';
    import 'leaflet.markercluster';
    import { getMarkerIcon } from './marker-icons';



    And this is how I call markerclustergroup:


    private markerClusterGroup = L.markerClusterGroup({
    showCoverageOnHover: false,
    spiderfyOnEveryZoom: true,
    zoomToBoundsOnClick: false,
    ...


    I'm using leaflet via installation (node modules)

    the markerclustergroup does work in development, but in the build it does not

    and if there's some interest on Dockerfile, here it is:

    FROM nginx:alpine

    COPY nginx.conf /etc/nginx/nginx.conf

    #COPY /dist/monitoramento-niesa/browser/* /usr/share/nginx/html#
    COPY /dist/monitoramento-niesa/browser/* /usr/share/nginx/html/monitoramento/

    CMD ["nginx", "-g", "daemon off;"]



    I use "npm run build" or "ng build" before calling "docker build -t my-app ." and "docker run -d -p 4200:80 --name frontend my-app"

    I've tried adding them into angular.json:

    "styles": [
    "@angular/material/prebuilt-themes/azure-blue.css",
    "node_modules/leaflet/dist/leaflet.css",
    "node_modules/leaflet.markercluster/dist/MarkerCluster.css",
    "node_modules/leaflet.markercluster/dist/MarkerCluster.Default.css",
    "src/styles.css"
    ],
    "scripts": [
    "node_modules/leaflet/dist/leaflet.js",
    "node_modules/leaflet.markercluster/dist/leaflet.markercluster.js"
    ]


    and I've also tried calling it on main.ts, but no success I've searched and tried every solution I could find, and none worked for me

    Continue reading...

Compartilhe esta Página