Skip to content

PMTiles vector source fails when mapbox-gl is loaded via npm bundler (Vite/Rollup/Webpack) #13677

Description

@whirano

mapbox-gl-js version

3.24.0

Browser and version

No response

Expected behavior

Description

PMTiles vector sources work correctly when Mapbox GL JS is loaded via CDN <script> tag, but fail with u is not defined error when the same version is imported as an npm package and bundled with Vite, Rollup, or Webpack.

Steps to reproduce

  1. Install mapbox-gl@3.24.0 via npm/yarn.
  2. Import and bundle with Vite (or any bundler).
  3. Add a PMTiles vector source:
map.addSource('test', {
  type: 'vector',
  url: 'https://docs.mapbox.com/mapbox-gl-js/assets/earthquakes.pmtiles'
});
  1. Observe error in console: u is not defined from loadTileProvider in the worker blob.

Actual behavior

Actual behavior

Worker fails to dynamically import the PMTiles provider plugin. The error occurs in both dev and production builds.

Root cause analysis

The TILE_PROVIDER_URLS config uses a relative path (/mapbox-gl-js/plugins/mapbox-gl-pmtiles-provider/v0.0.2/mapbox-gl-pmtiles-provider.js).

  • When loaded via CDN, this resolves to https://api.mapbox.com/mapbox-gl-js/plugins/....
  • However, when bundled via npm, the Worker blob's origin becomes blob:http://localhost:..., so the dynamic import() resolves to http://localhost/mapbox-gl-js/plugins/... which doesn't exist.

Workaround

  • Use CDN <script> tag instead of npm package.
  • Or, use MapLibre GL JS with the pmtiles library.

Environment

  • mapbox-gl: 3.24.0
  • Bundler: Vite 8 (also reproduced with production build, so not Vite-specific)
  • Browser: Chrome
  • OS: Linux

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