mapbox / mapbox/mapbox-gl-js

Place names/labels not displaying on production: Uncaught ReferenceError: i is not defined

Open
#13,372 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :lady_beetle:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

Screenshot 2024-12-24 at 7 24 00 PM

**mapbox-gl-js version**: ^3.1.2
"react": "^18.2.0",

**browser**: All browsers

### Steps to Trigger Behavior

Unable to reproduce behavior locally, only occurs on production environment

```
### Expected Behavior
Map to render with place names/labels.
### Actual Behavior
Map not rendering with place names/labels.

import React, { useEffect, useRef } from "react";
import { useParams } from "react-router-dom";
import mapboxgl from "mapbox-gl";
import { api } from "api";
import { errors, errorsCodes, globals } from "common";
import { MAP_BOX_CLIENT_ID } from "../../config";
import "../map/_map.scss";
import "mapbox-gl/dist/mapbox-gl.css";

mapboxgl.accessToken = MAP_BOX_CLIENT_ID;

function Map(
{
shopArea,
pin,
setPin,
draggable = false,
setAddress,
setShowAlert,
setErrorMsg,
}
) {
const mapContainer = useRef(null);
const map = useRef(null);
const marker = useRef(null);
const {token} = useParams();
let coordinates = [pin?.longitude, pin?.latitude];

const resetAddress = () => {
setAddress(globals.DEFAULT_ADDRESS);
}

async function onDragEnd() {
setShowAlert(false);
const lngLat = marker.current.getLngLat();
coordinates = [lngLat?.lng, lngLat?.lat];
setPin({
longitude: lngLat?.lng,
latitude: lngLat?.lat,
});
marker.current.setLngLat(coordinates);
try {
const addressDetail = await api.getAddress({
token,
params: {longitude: lngLat?.lng, latitude: lngLat?.lat},
});
const plot = addressDetail.plot;
const area = addressDetail.area;
let error;
if (area.id !== shopArea?.id) {
error = errors.ADDRESS_OUT_OF_RANGE(shopArea?.area);
}
else if (!plot?.point) {
error = errors.ADDRESS_NOT_FOUND;
}
if (error) {
setErrorMsg(error);
setShowAlert(true);
resetAddress();
return;
}
setAddress({
plot: plot?.plot_number,
block: plot?.block?.name,
sector: plot?.block?.sector,
street: plot?.street,
});
} catch (error) {
if (error?.response?.status === errorsCodes.NOT_FOUND_CODE) {
setErrorMsg(errors.AREA_OUT_OF_RANGE);
resetAddress();
setShowAlert(true);
}
}
}

useEffect(() => {
if (!map.current) {
map.current = new mapboxgl.Map({
container: mapContainer.current,
style: "mapbox://styles/mapbox/streets-v12",
center: coordinates,
zoom: 14,
});
}

if (!marker.current) {
marker.current = new mapboxgl.Marker({
color: "red",
draggable: draggable,
})
.setLngLat(coordinates)
.addTo(map.current);
} else {
!draggable && marker.current.setLngLat(coordinates);
}
draggable && marker.current.on("dragend", onDragEnd);
}, []);

useEffect(() => {
const handleClick = (e) => {
window.open(`https://www.google.com/maps?q=${pin?.latitude},${pin?.longitude}`, '_blank');
};

if (map?.current) {
map.current?.on('click', handleClick);
}

return () => {
if (map?.current) {
map.current?.off('click', handleClick);
}
};
}, [pin]);

return (




);
}

export default Map;
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied React Map component and the production console error, then compare the production build and mapbox-gl 3.1.2 setup with a minimal reproduction. Done means the production map renders place names and labels without the ReferenceError; the report currently provides no repository file or test to run and says the problem cannot be reproduced locally.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.