question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API access token is required to use Mapbox GL

See original GitHub issue

Tell me please. Why do I receive this error: Error: "An API access token is required to use Mapbox GL. See https://www.mapbox.com/api-documentation/#access-tokens-and-token-scopes" Any other token doesn’t work either

Example: https://stackblitz.com/edit/react-ts-fe73xz

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:21

github_iconTop GitHub Comments

11reactions
brianvandenakkercommented, Mar 26, 2022

It looks like versions earlier that 7.0 used: mapboxApiAccessToken=YOUR_ACCESS_TOKEN. to set the API key.

v7.0 uses: mapboxAccessToken=YOUR_ACCESS_TOKEN. As described here[https://github.com/visgl/react-map-gl/blob/29aa2098febf1e6b8bbfd2caecb3745b3d4d82a9/docs/upgrade-guide.md]

That change fixed it for me.

4reactions
vfoniccommented, May 9, 2021

I’ve finally managed to fix this issue. I’m also using Vite (Rollup) bundler.

This is what worked for me:

// somewhere in your app code before using mapbox:
import * as mapboxgl from 'mapbox-gl';
(mapboxgl as any).accessToken = mapboxAccessToken;
// vite.config.js
export default defineConfig({
  // ...
  resolve: {
    alias: [
      // ...
      {
        find: /^react-mapbox-gl/,
        replacement: 'react-mapbox-gl/lib',
      },
    ],
  },
});

mapbox-gl 1.13.1 react-mapbox-gl 5.1.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why mapbox-gl.js:29 Uncaught Error: An API access token is ...
The question doesn't really make a lot of sense since it is trying to use the library in the way that is not...
Read more >
A valid API access token is required to use Mapbox data
You need a mapbox API token to be able to access the mapStyle via MapBox. MapBox should have documentation on how to do...
Read more >
react-map-gl | About Mapbox Tokens
mapbox -gl@1.x or maplibre-gl - requires an access token only if you load the map styles and tiles from Mapbox's data service. See...
Read more >
How to use the mapbox-gl.accessToken function in ... - Snyk
json') { var geojsonData = require(path.resolve(mapsFolder, file)); stl_json.sources['jsonsource'] = { type: 'geojson', data: geojsonData }; } }); // console.
Read more >
Using Mapbox GL JS with React - LogRocket Blog
In this post, learn to use react-map-gl to build two variations of map ... the Mapbox token to access the Mapbox API and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found