Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

94
Vistas
react-map-gl - Enviromental variable doesn't pass a token

DEVELOPER SERVER if I copy and paste my api token directly to .env

NEXT_PUBLIC_MAPBOX_API="my-secret-mapbox-gl-api-key"

and use it like

mapboxAccessToken={process.env.NEXT_PUBLIC_MAPBOX_API}

and it doesn't render the map and there is an error in dev tools

next-dev.js?3515:24 Error: An API access token is required to use Mapbox GL. See https://www.mapbox.com/api-documentation/#access-tokens-and-token-scopes
    at t.RequestManager._makeAPIURL (mapbox-gl.js?0c80:31:423135)
    at t.RequestManager.normalizeStyleURL (mapbox-gl.js?0c80:31:420958)
    at ei.loadURL (mapbox-gl.js?0c80:35:102600)
    at Map._updateStyle (mapbox-gl.js?0c80:35:458753)
    at Map.setStyle (mapbox-gl.js?0c80:35:458172)
    at new Map (mapbox-gl.js?0c80:35:448583)
    at Mapbox._initialize (mapbox.js?699b:222:1)
    at new Mapbox (mapbox.js?699b:128:1)
    at eval (map.js?48e9:61:1)

I tried to run a dev server again it hasn't helped

I use "next": "12.2.2".

hmm? I've also tried REACT_APP_MAPBOX_ACCESS_TOKEN instead of NEXT_PUBLIC then in Map component the prop: mapboxAccessToken={process.env.REACT_APP_MAPBOX_ACCESS_TOKEN} and it still hasn't helped! :/

     <Map
              initialViewState={{
                longitude: 21.338631,
                latitude: 50.102242,
                zoom: 11,
              }}
              style={{
                overflow: "hidden",
              }}
              mapStyle={mapboxThemeStyle}
              mapboxAccessToken="my-secret-api-token-without-env-and-it-works" // 
              id="map"
              tabIndex="-1"
            >
              <Marker
                longitude={21.338631}
                latitude={50.102242}
                color="#206ea0"
              />
            </Map>

Tried add env to .env.local like NEXT_PUBLIC_MY_MAPBOX_API_TOKEN="pk.xxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxx-xxxxxxxxxx" and it works! thank you @Heet Vakharia!

react-map-gl: https://github.com/visgl/react-map-gl

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

According to Next.JS docs for envs in Frontend, you need to add your envs in the .env.local file and All ENVS should start with NEXT_APP_ (which you have already done ) and then don't forget to restart the app in terminal

https://nextjs.org/docs/basic-features/environment-variables

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda