Skip to content

v3.25.0: Switching the ESM entry point to named exports not compatible with latest MapboxSearchBox (search-js-web) #13696

Description

@enzedonline

mapbox-gl-js version

v3.25.0

Browser and version

Chrome Version 149.0.7827.200

Expected behavior

After switching the ESM entry point to named exports (import * as mapboxgl from 'mapbox-gl/esm'), binding the Map object to the MapboxSearchBox object should be possible.

Actual behavior

After creating the map object using the new ESM entry point, trying to bind the map to the search box throws a type error:

import * as mapboxgl from 'mapbox-gl/esm';
...
        this.map = new mapboxgl.Map;
        ...
        const searchBox = new MapboxSearchBox();
        searchBox.bindMap(this._map!);
Argument of type 'import("/node_modules/mapbox-gl/dist/esm/mapbox-gl").Map' is not assignable to parameter of type 'mapboxgl.Map'.
  Excessive stack depth comparing types 'Map$1' and 'Map$1'.

The source of the issue is the mapboxgl import path in the MapboxSearchBox component @mapbox/search-js-web/dist/components/MapboxSearchBox.d.ts which is still using the legacy path (import mapboxgl from 'mapbox-gl';).

The workaround is to cast the map instance as any, but an update to the search-js-web is needed to reflect the new import path.

        searchBox.bindMap(this._map! as any);

Link to the demonstration

No response

Steps to trigger the unexpected behavior

No response

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions