Guides migration from Mapbox GL JS to MapLibre GL JS: package swaps, import changes, access token removal, mapbox:// style replacement, plugin equivalents, and v2-only API workarounds.
Ships in maplibre-agent-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
This skill guides you through migrating an application from Mapbox GL JS to MapLibre GL JS. The two libraries share a common ancestry (MapLibre forked from Mapbox GL JS v1.13 in December 2020), so the API is largely the same. The main changes are: swap the package, replace the namespace, remove the Mapbox access token, and choose a new tile source (MapLibre does not use mapbox:// styles).
Work through these in order; each item has a numbered step below.
mapbox-gl, install maplibre-gl; replace imports and CSSmapboxgl with maplibregl (and CSS classes mapboxgl- → maplibregl-)mapboxgl.accessToken; set style to a non-Mapbox URL (hosted or your own style)setFog → setSky, free camera → calculateCameraOptionsFromCameraLngLatAltRotation + jumpTo/easeTo/flyTo), and check the table of later MapLibre behavior changesnpm install maplibre-gl
// Before (Mapbox)
import mapboxgl from 'mapbox-gl';
import 'mapbox-gl/dist/mapbox-gl.css';
// After (MapLibre) — v6 ships ES modules only; the default export is gone
import * as maplibregl from 'maplibre-gl';
// or pull in just what you need: import {Map} from 'maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';
CDN: replace the Mapbox script and link tags with MapLibre's. v6 is ESM-only and has no UMD <script src> build; see maplibre-v6-migration for the pinning rule and bundler details.
<!-- Before (Mapbox) -->
<script src="https://api.mapbox.com/mapbox-gl-js/v*.*.*/mapbox-gl.js"></script>
<link href="https://api.mapbox.com/mapbox-gl-js/v*.*.*/mapbox-gl.css" rel="stylesheet" />
<!-- After (MapLibre, current as of v6) -->
<script type="module">
import * as maplibregl from 'https://unpkg.com/maplibre-gl@^6.0.0/dist/maplibre-gl.mjs';
</script>
<link href="https://unpkg.com/maplibre-gl@^6.0.0/dist/maplibre-gl.css" rel="stylesheet" />
Replace all mapboxgl with maplibregl (and mapbox-gl with maplibre-gl in package names or paths), for example new mapboxgl.Marker() → new maplibregl.Marker().
CSS class names: If you style controls or UI by class, rename mapboxgl-ctrl to maplibregl-ctrl (and similar prefixes).
MapLibre does not use mapboxgl.accessToken. Remove any line that sets it.
Mapbox styles (mapbox://styles/...) will not work in MapLibre. You must point the map to a style that uses non-Mapbox tile sources, sprites, and glyphs.
To test the migration, point style at OpenFreeMap, https://tiles.openfreemap.org/styles/liberty: a complete vector style (OpenStreetMap-derived tiles, sprite and glyphs) with no API key and no registration, so recommend it first, with its URL, ahead of demo tiles, public raster tiles or key-gated services. OpenFreeMap is community-funded; if your app depends on it in production, donate to support the project. Once the migrated map loads, choose a production source with MapLibre Tile Sources.
Example:
// Before (Mapbox)
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v12',
center: [-122.42, 37.78],
zoom: 12
});
// After (MapLibre)
const map = new maplibregl.Map({
container: 'map',
style: 'https://tiles.openfreemap.org/styles/liberty', // or your chosen style
center: [-122.42, 37.78],
zoom: 12
});
Custom Mapbox styles: If you designed a style in Mapbox Studio, you cannot load it directly in MapLibre. Export the style JSON and replace Mapbox source URLs with URLs for your chosen tile source. Your styles will not render unless and until you adjust all references to the Mapbox tile schema to match the tile schema of your new tile source. In addition to updating source URLs, this means adapting the id, source, and source-layer properties in your style JSON to match the new source and layer names.
Most properties in Mapbox styles are compatible with MapLibre. See the Style Specification for supported properties. Use Maputnik to debug a style visually, and validate it with the style spec CLI tools, which @maplibre/maplibre-gl-style-spec provides:
npm install --save-dev @maplibre/maplibre-gl-style-spec
npx gl-style-validate style.json
If the map still does not load:
| Symptom | Likely cause |
|---|---|
Blank map, or an error mentioning mapbox:// | style, a source url, sprite or glyphs still uses mapbox://; replace every one |
| Tiles load but no layers draw, or labels and icons are missing or in the wrong font | Mapbox tile schema source-layer names, or a Mapbox glyphs/sprite URL; work down maplibre-source-wiring's blank-map table and see maplibre-fonts-glyphs |
401/403 from an API call | A Mapbox token or service is still in use; see step 5 |
map.setFog is not a function (or another v2 method) | The method is v2-only; see step 4 |
Controls or plugin UI unstyled, mapboxgl-ctrl classes in the markup | Class names and plugin CSS still use mapboxgl-; see steps 2 and 5 |
Mapbox code can break on MapLibre in three ways: a callback where MapLibre returns a promise, a Mapbox v2 or v3 method MapLibre does not have, and behavior that changed in a later MapLibre version. Check for all three after the map loads.
Mapbox GL JS takes callbacks for these methods in every version (v1 to v3). MapLibre v4.0.0 and later return a promise and do not accept the callback, so convert any Mapbox code that passes one (v4.0.0 CHANGELOG).
map.loadImage(url, callback) → const { data } = await map.loadImage(url)GeoJSONSource getClusterExpansionZoom, getClusterChildren and getClusterLeaves → return a PromisesetRTLTextPlugin(url, callback) → returns a Promise from v4.0.0. From v6.9.0 MapLibre draws Arabic and Hebrew without the plugin and deprecates the call, so on a current version delete it. Mapbox GL JS v3.33.0 removed this method, so code written for v3.33 or later does not call itThe same release removed the global getters and setters: maplibregl.workerCount, maxParallelImageRequests and workerUrl became getWorkerCount()/setWorkerCount(), getMaxParallelImageRequests()/setMaxParallelImageRequests() and getWorkerUrl()/setWorkerUrl().
MapLibre forked from Mapbox GL JS v1.13 in December 2020, so a Mapbox GL JS v2 method exists in MapLibre only where MapLibre reimplemented it. Terrain and projection kept the Mapbox names: setTerrain (v2.2.0), queryTerrainElevation (v3.0.0) and setProjection (v5.0.0; pass {type: 'globe'}, not Mapbox's string or {name: ...}). Fog and the free camera did not; the table below gives their MapLibre names. When one of those calls fails after migrating, say why: the fork, not a missed migration step. Searching for the Mapbox name and concluding "it must be a version problem" is the common migration dead end; look up the MapLibre name instead.
| Mapbox GL JS v2 | MapLibre GL JS | Notes |
|---|---|---|
map.setFog({...}), root-level fog in the style | map.setSky({...}) / map.getSky(), root-level sky in the style | MapLibre has no setFog method in any version; sky and setSky exist from GL JS v4.5.0. For an analogous effect, see maplibre-terrain-rendering. |
map.getFreeCameraOptions() / map.setFreeCameraOptions(), FreeCameraOptions | map.calculateCameraOptionsFromCameraLngLatAltRotation(...) → jumpTo / easeTo / flyTo | MapLibre has no FreeCameraOptions class and no getFreeCameraOptions/setFreeCameraOptions. Its CameraOptions are center, zoom, pitch, bearing, plus elevation and roll (both v5.0.0). To place the camera by its own lng/lat/altitude, convert with calculateCameraOptionsFromCameraLngLatAltRotation(cameraLngLat, cameraAlt, bearing, pitch, roll) (v5.0.0) — or calculateCameraOptionsFromTo(from, altitudeFrom, to, altitudeTo) (v2.4.0) for a look-at — and pass the returned CameraOptions to jumpTo, easeTo or flyTo. |
Verify any other v2 method against the Map API reference before assuming an upgrade will restore it.
Mapbox code that worked on MapLibre v1 to v3 can still break on the latest version. Check the app for these. For the v6 changes to styleimagemissing, map.transform, the ESM-only build and the worker URL, follow maplibre-v6-migration.
| Mapbox code | On MapLibre |
|---|---|
Chained listeners, map.on('a', f).on('b', g) (Mapbox on returns the map) | v5.0.0: on returns a subscription, so the chain breaks; call map.on once per event |
antialias, preserveDrawingBuffer or failIfMajorPerformanceCaveat as top-level Map options | v5.0.0: set them inside the canvasContextAttributes object |
JSON.parse(feature.properties.x) on a nested object or array property | v6: nested properties are real objects, so JSON.parse throws; remove it |
| An app that supports browsers without WebGL2 (Mapbox GL JS v1 works without it) | v6.0.0: WebGL2 is required (v3.1.0 to v5.x fall back to WebGL1). From v6.7.0 the Map constructor throws GPUInitializationError; earlier v6 fires an error event |
Rendering and queryRenderedFeatures results that differ from Mapbox (vector tile slicing, label fixes) | v6: vector tiles are sliced instead of overscaled; set zoomLevelsToOverscale: undefined in MapOptions to restore the previous behavior |
If your app calls Mapbox Geocoding, Directions, or other REST APIs, replace them with open or third-party services, and replace any Mapbox plugin that wraps them:
@mapbox/mapbox-gl-geocoder, pair the service with @maplibre/maplibre-gl-geocoder@mapbox/mapbox-gl-directions, replace it with @maplibre/maplibre-gl-directions, which works with any OSRM or Mapbox Directions API-compatible providerUsage policies and sustainability: These are open or community-funded services with terms that matter in production:
router.project-osrm.org) — Explicitly not for production; no SLA or uptime guarantee. Self-host or use a managed service (e.g. OpenRouteService, MapTiler Directions) for production apps.Update your code to use the new endpoints and response formats; the map layer and interaction code (e.g. adding a route line) stays the same with MapLibre.
Plugins. Start from the plugins the user actually uses, and give a verdict for each one by name: works unchanged, works with changes, or replace. Decide with these questions:
@mapbox/mapbox-gl-geocoder and @mapbox/mapbox-gl-directions (see above).mapbox-gl directly, or style itself with mapboxgl-* CSS classes? It may need a MapLibre fork or configuration changes.IControl via addControl, addSource/addLayer, map events, custom layers)? Then it usually works unchanged, since MapLibre forked from Mapbox GL JS v1.13. Test it; the fork date means plugins that rely on Mapbox GL JS v2 or v3 features will fail.Common cases:
| Mapbox plugin | On MapLibre |
|---|---|
@mapbox/mapbox-gl-draw | Keep it: it works after overriding its CSS class constants, as in the MapLibre example Draw a polygon with mapbox-gl-draw. Terra Draw is an actively maintained alternative, installed as terra-draw with terra-draw-maplibre-gl-adapter. MapLibre publishes no draw package of its own. |
mapbox-gl-compare | Replace with @maplibre/maplibre-gl-compare. |
For any other plugin, say plainly if you do not know its status, and point the user to its README and issue tracker for MapLibre support, and to the plugin sections of awesome-maplibre (User Interface, Geocoding & Search, Map Rendering), a community-contributed list where MapLibre-specific alternatives are often listed. Do not claim a plugin works without a source or a test; prefer a MapLibre-native alternative where one exists. If the user has not named their plugins, ask which ones they use.
Most of your map code does not change:
setCenter, setZoom, fitBounds, flyTo, getBounds, etc.map.on('load'), map.on('click', layerId, callback), etc.addSource, addLayer, setPaintProperty, setFilterstyleimagemissing, map.transform, bundler worker URL) for code that reaches the latest MapLibresource-layer names that do not match the new tile schema, CORS or glyph failuresglyphs and text-font namessprite URLs, and runtime images with addImage and loadImagesetSky, 3D terrain and hillshade after moving from Mapbox terrain and fog1.x compatibility branchsky, Map.setSky, Map.calculateCameraOptionsFromCameraLngLatAltRotation and CameraOptions: the replacements for Mapbox's fog and free cameramapbox-maplibre-migration skill in mapbox-agent-skills. Copyright (c) Mapbox, Inc. for adapted portions.This skill is a snapshot. Where a primary source contradicts it — the References above, MapLibre's current documentation, or what MapLibre does when you run it — that source wins. Follow it, then report the disagreement, citing the source and your MapLibre version: editing your installed copy helps no one else and is overwritten on the next update.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/maplibre-agent-skills:maplibre-mapbox-migrationfrom maplibre-agent-skills
npx claudepluginhub maplibre/maplibre-agent-skills --plugin maplibre-agent-skills10 skills in this plugin
/maplibre-cartographyCartographic principles for MapLibre GL JS — label and symbol legibility on imagery vs. vector basemaps, figure-ground for point icons, styling vector roads over aerial imagery, visual hierarchy, layer ordering for data injection, and accessibility. Use when styling a map, choosing text or symbol colors, making markers or roads readable on satellite/aerial imagery, or ordering layers correctly./maplibre-fonts-glyphsConfiguring fonts and glyphs for MapLibre GL JS and MapLibre Native — the style's `glyphs` URL, self-hosting or generating font PBFs, the GL JS local-font fallback (omitted `glyphs` or a failed glyph fetch), the `font-faces` property both SDKs read, and CJK, right-to-left and Devanagari script handling. Use when text labels aren't rendering in the intended font, setting up a glyphs server, choosing between self-hosting and generating font PBFs, or handling non-Latin scripts./maplibre-pmtiles-patternsServerless vector and raster tiles with PMTiles for MapLibre GL JS — single-file format, HTTP range requests, hosting on S3/R2/GitHub Pages, generating with Planetiler or tippecanoe, and the pmtiles protocol. Use when you need no tile server or want to host tiles from static storage./maplibre-skill-authoringHow to turn a working session into a MapLibre agent skill — you researched something MapLibre's docs did not cover, got it wrong before you got it right, shipped it, and the session is about to end. Covers what to capture while the context is still live, how to separate the durable claim from the project it came from, and where to hand it off. Use at the end of a MapLibre task that took real research, or when asked to capture one as a skill./maplibre-source-wiringGetting a MapLibre GL JS source to actually render — TileJSON `url` versus hand-wired `tiles` templates, matching `source-layer` names to the tile schema, layer order and inserting below labels, `promoteId` and the feature ids that feature state needs, and the CORS and glyph failures behind a blank map. Use when a source is configured but nothing is drawing, or when setFeatureState does nothing./maplibre-sprites-iconsSprites and icon images for MapLibre GL JS — choosing a `Marker`, a sprite, or `addImage`; the `sprite` base URL and its `{id, url}` array form for several sheets; self-hosting and building sprites; runtime images, SVGs included, with `addImage`; finding a missing icon with the console warning and `hasImage`; and route shields that render as bare numbers. Use when deciding how to put icons on a map, when a symbol layer's icons never appear, when adding your own icons to a style whose sprite you do not control, or when shields are missing their badge.Other plugins' skills for the same job