mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

dist/mapbox-gl.d.ts imports @mapbox/point-geometry but it is no longer a declared dependency (3.25.0)

Open nyates42 opened this issue 5 months ago • 2 comments

mapbox-gl-js version

3.25.0

Browser and version

No response

Expected behavior

After a normal npm install, the bundled TypeScript types resolve and compile, the way they did in 3.24.x.

Actual behavior

After bumping from 3.24.1 to 3.25.0, TypeScript can't resolve the Point type that the public API uses (for example MapMouseEvent.point). The shipped dist/mapbox-gl.d.ts still starts with:

import Point from '@mapbox/point-geometry'; but 3.25.0 removed all direct dependencies from package.json, so @mapbox/point-geometry is no longer installed for consumers. The published types point at a package that the library no longer pulls in.

This isn't only point-geometry. dist/mapbox-gl.d.ts imports from ten external packages that are no longer dependencies:

import { isSupported as supported } from '@mapbox/mapbox-gl-supported';
import Point from '@mapbox/point-geometry';
import TinySDF from '@mapbox/tiny-sdf';
import { VectorTile, VectorTileFeature, VectorTileLayer } from '@mapbox/vector-tile';
import { BindingApi, BindingParams, ButtonApi, FolderApi, FolderParams } from '@tweakpane/core';
import { MultiPolygon, Polygon } from 'geojson';
import { mat2, mat3, mat4, quat, vec2, vec3, vec4 } from 'gl-matrix';
import KDBush from 'kdbush';
import { PbfReader } from 'pbf';
import { PotpackBox } from 'potpack';

Most of those usually happen to be present in a real app through other libraries, so they don't blow up. @mapbox/point-geometry is the one that commonly isn't, or is only present as an old untyped copy, so it's the one that breaks.

For reference, 3.24.1 declared it as a runtime dependency and 3.25.0 dropped everything:

$ npm view [email protected] dependencies
{ ... '@mapbox/point-geometry': '^1.1.0', ... }
$ npm view [email protected] dependencies
(empty)

The relevant changelog line for 3.25.0 is "Remove all direct dependencies from package.json slightly improving NPM install size and time." The runtime bundle is self contained so dropping deps is fine for runtime, but the published .d.ts was not updated to match.

Link to the demonstration

No response

Steps to trigger the unexpected behavior

Minimal case:

npm init -y npm i [email protected] typescript Add index.ts:

import type { MapMouseEvent } from 'mapbox-gl';
export function handler(e: MapMouseEvent) {
  return e.point.x;
}

npx tsc --noEmit index.ts With default settings you get a module resolution failure pointing at the bundled types:

node_modules/mapbox-gl/dist/mapbox-gl.d.ts:2:19 - error TS2307: Cannot find module '@mapbox/point-geometry' or its corresponding type declarations. If skipLibCheck is on, that lib error is hidden, but e.point then resolves to an unresolved type and anything reading .point.x / .point.y becomes unsafe.

The variant we hit in our own app: we also use deck.gl, which pulls in @mapbox/vector-tile, which depends on @mapbox/[email protected] (an old version with no bundled types). That untyped 0.1.0 gets hoisted to the top of node_modules, so mapbox-gl's import resolves to it instead of failing outright. Because it has no types, event.point ends up as an error type and trips typescript-eslint:

@typescript-eslint/no-unsafe-member-access: Unsafe member access .x on a type that cannot be resolved.
@typescript-eslint/no-unsafe-assignment: Unsafe assignment of an error typed value.

So depending on what else is in the tree, the same root cause shows up either as TS2307 or as a pile of no-unsafe lint errors.

Relevant log output


nyates42 avatar Jun 22 '26 05:06 nyates42

Current workaround:

Install a typed copy directly:

npm i -D @mapbox/point-geometry@^1.1.0 or pin back to [email protected], where it was still a declared dependency.

nyates42 avatar Jun 22 '26 05:06 nyates42

Hi @nyates42,

Thanks for flagging this. This is fixed in https://github.com/mapbox/mapbox-gl-js/commit/70486667c3dedf7936f35288edce2458d557734f and will be available in the upcoming v3.26.0-rc.1 release. I'll close this now, but please feel free to tag me if that doesn't resolve the issue.

stepankuzmin avatar Jun 25 '26 12:06 stepankuzmin