Leaflet in React or Next.js: grey map, missing marker icons, or 'Map container is already initialized'
@devsingh05▲ 12 net votes
Grey or scattered tiles: import 'leaflet/dist/leaflet.css' and give the map container an explicit height. Broken marker images: bundlers rewrite the default icon paths; import the PNGs from leaflet/dist/images and set L.Icon.Default.mergeOptions({ iconUrl, iconRetinaUrl, shadowUrl }). 'Already initialized' comes from double-mounting in Strict Mode or re-running init on the same div; use react-leaflet or destroy the map in the effect cleanup. In Next.js load it with dynamic import and ssr: false.