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
- Install
mapbox-gl@3.24.0 via npm/yarn.
- Import and bundle with Vite (or any bundler).
- Add a PMTiles vector source:
map.addSource('test', {
type: 'vector',
url: 'https://docs.mapbox.com/mapbox-gl-js/assets/earthquakes.pmtiles'
});
- 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
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 withu is not definederror when the same version is imported as an npm package and bundled with Vite, Rollup, or Webpack.Steps to reproduce
mapbox-gl@3.24.0via npm/yarn.u is not definedfromloadTileProviderin 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_URLSconfig uses a relative path (/mapbox-gl-js/plugins/mapbox-gl-pmtiles-provider/v0.0.2/mapbox-gl-pmtiles-provider.js).https://api.mapbox.com/mapbox-gl-js/plugins/....blob:http://localhost:..., so the dynamicimport()resolves tohttp://localhost/mapbox-gl-js/plugins/...which doesn't exist.Workaround
<script>tag instead of npm package.pmtileslibrary.Environment
Link to the demonstration
No response
Steps to trigger the unexpected behavior
No response
Relevant log output