js-markerwithlabel icon indicating copy to clipboard operation
js-markerwithlabel copied to clipboard

Error on initialisation: Uncaught TypeError: Class constructors cannot be invoked without 'new'

Open portbury opened this issue 8 months ago • 20 comments

Recently, all attempts to initialise a MarkerWithLabel fail with:

index.dev.js:260  Uncaught TypeError: Class constructors cannot be invoked without 'new'
    at new MarkerSafe (index.dev.js:260:32)
    at new MarkerWithLabel (index.dev.js:292:13)

I discovered this issue in our own environment, but the exact same issue occurs in all four of the Examples provided in the GitHub Readme: https://github.com/googlemaps/js-markerwithlabel?tab=readme-ov-file#example

I have tried in Firefox 135.0.1, Edge 133.0.3065.92 and Chrome 134.0.6998.45 on both macos and Windows - all produce the same error.

portbury avatar Mar 06 '25 06:03 portbury

We have same issue Full stack trace from console.log

Image

andreasringdal avatar Mar 06 '25 07:03 andreasringdal

same problem as well, the entire web portal is blocked because I use markers with labels

Iameora avatar Mar 06 '25 07:03 Iameora

We are experiencing the same issue where markers are not displaying in our production applications. With an older version of the Google Maps JS API, such as 3.59, it works. This issue does not seem to be related to the report mentioned ...

As of February 21st, 2024, google.maps.Marker is deprecated. Please use google.maps.marker.AdvancedMarkerElement instead. At this time, google.maps.Marker is not scheduled to be discontinued, but google.maps.marker.AdvancedMarkerElement is recommended over google.maps.Marker. While google.maps.Marker will continue to receive bug fixes for any major regressions, existing bugs in google.maps.Marker will not be addressed. At least 12 months notice will be given before support is discontinued. Please see https://developers.google.com/maps/deprecations for additional details and https://developers.google.com/maps/documentation/javascript/advanced-markers/migration for the migration guide.

davidpadych avatar Mar 06 '25 08:03 davidpadych

Can confirm that adding v=3.59 when including works as a temporary fix

andreasringdal avatar Mar 06 '25 08:03 andreasringdal

They have changed something in a new 3.60.3 version, however, there is no changelog https://developers.google.com/maps/documentation/javascript/releases

AndrewYehozha avatar Mar 06 '25 08:03 AndrewYehozha

I confirm that it is still functional in version 3.60.2. This should be reported to Google because they apparently released patch 3.60.3 and it broke. Do you have any suggestions on where else to report this?

davidpadych avatar Mar 06 '25 08:03 davidpadych

Can confirm that adding v=3.59 when including works as a temporary fix

How can i do this here?

Thanks!

kostis1313 avatar Mar 06 '25 09:03 kostis1313

AndrewYehozha avatar Mar 06 '25 09:03 AndrewYehozha

Impacting us too. Version pin to 3.59 resolved it for us

DanOrsborne avatar Mar 06 '25 09:03 DanOrsborne

I confirm that it is still functional in version 3.60.2. This should be reported to Google because they apparently released patch 3.60.3 and it broke. Do you have any suggestions on where else to report this?

Does v= use all levels of the version parameter? Works with v=3.59 but not with v=3.60.2. Is it using the latest patch build available for the minor version?

andreasringdal avatar Mar 06 '25 09:03 andreasringdal

don't know why google map js SDK v3.60 use es6 syntax directly, it's breaking change but release in v3 with weekly mode

is js-markerwithlabel planning support > v3.6 ?

bigbossx avatar Mar 06 '25 10:03 bigbossx

Same here, crashed production for us until we pushed an emergency hotfix to force v3.59 in the URL.

nicolus avatar Mar 06 '25 10:03 nicolus

Emergency hot fix with 3.59 fixed it. Thanks!!

Sisok avatar Mar 06 '25 14:03 Sisok

For reference, if anybody is using the react-wrapper and want to pin a version as a workaround:

// Rename to temp disable typing
import { Wrapper as MapWrapper } from "@googlemaps/react-wrapper";

<MapWrapper version="3.59"...

mattlisiv avatar Mar 06 '25 14:03 mattlisiv

Switching from new MarkerWithLabel({ to new google.maps.Marker({ resolved the issue for me as a temporary hotfix. Obviously I lost the "label" portion of the marker but that was ok given the pins were not loading otherwise.

I also just tested pinning to v=3.59 and reverting back to new MarkerWithLabel({ and that also works as others have already confirmed.

mikemonaco avatar Mar 06 '25 15:03 mikemonaco

I've reporting this issue to Google: https://issuetracker.google.com/issues/401168185

Please upvote it!

mikemonaco avatar Mar 06 '25 15:03 mikemonaco

It's also worth noting, Google only maintains four fully supported versions at any given time, so pinning to 3.59 is ok for now, but eventually that will roll off the supported versions and requesting v=3.59 will result in you being served the latest version. You can verify this by trying to pin to v=3.56 and notice the MarkerWithLabel issue returns.

TLDR; use the v=3.59 workaround as a temporary fix only.

mikemonaco avatar Mar 06 '25 16:03 mikemonaco

Same problem here! Defining the version to 3.59 fixed for now.

fernandomantoan avatar Mar 06 '25 17:03 fernandomantoan

They rolled back to version 3.60.2... no hot fix needed anymore see https://issuetracker.google.com/issues/401168185

thx @mikemonaco

davidpadych avatar Mar 06 '25 18:03 davidpadych

In case this is useful for the devs of this library.

I managed to solve this issue by updating the MarkerWithLabel code.

Replacing the weird custom extend method

function extend(type1, type2) {
        // eslint-disable-next-line prefer-const
        for (let property in type2.prototype) {
            type1.prototype[property] = type2.prototype[property];
        }

with code properly extending the existing maps classes. (using ES6 extends) e.g:

class MarkerSafe extends google.maps.Marker {
  constructor(options) {
    super(options);
  }
}

It works perfectly with the rolled-back javascript maps version as well.

FifoTheHein avatar Mar 07 '25 10:03 FifoTheHein