Problems with leaflet marker in production #104
                  
                    
                      SashaLifashkin
                    
                  
                
                  started this conversation in
                General
              
            Replies: 2 comments 2 replies
-
| Hello @SashaLifashkin , I think the issue is related to this one: Leaflet/Leaflet#4968 | 
Beta Was this translation helpful? Give feedback.
                  
                    1 reply
                  
                
            -
| in 2025 with astro import L from "leaflet";
import "leaflet-gesture-handling";
// Manual icon import
import defaultMarkerIconRetinaUrl from "leaflet/dist/images/marker-icon-2x.png";
import defaultMarkerIconUrl from "leaflet/dist/images/marker-icon.png";
import defaultMarkerShadowUrl from "leaflet/dist/images/marker-shadow.png";
// This is the workaround of workaround for dev because leaflet have a bad concatenation
if (import.meta.env.DEV) {
  L.Icon.Default.imagePath = "";
}
// ok in prod but in dev need imagePath = ""
L.Icon.Default.mergeOptions({
    iconUrl: defaultMarkerIconUrl.src,
    iconRetinaUrl: defaultMarkerIconRetinaUrl.src,
    shadowUrl: defaultMarkerShadowUrl.src,
});or custom icone like : https://leafletjs.com/examples/custom-icons/ overwrite default icon ! import L from "leaflet";
import "leaflet-gesture-handling";
// Manual icon import
import defaultMarkerIconRetinaUrl from "leaflet/dist/images/marker-icon-2x.png";
import defaultMarkerIconUrl from "leaflet/dist/images/marker-icon.png";
import defaultMarkerShadowUrl from "leaflet/dist/images/marker-shadow.png";
const defaultIcon = L.icon({
    iconUrl: defaultMarkerIconUrl.src,
    iconRetinaUrl: defaultMarkerIconRetinaUrl.src,
    shadowUrl: defaultMarkerShadowUrl.src,
    iconSize: [25, 41],
    iconAnchor: [12, 41],
    popupAnchor: [1, -34],
    shadowSize: [41, 41],
  });
  
  // ....
  const marker = L.marker([lat, lon], { icon: persoIcon });
  marker.addTo(map);
  // .... | 
Beta Was this translation helpful? Give feedback.
                  
                    1 reply
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
I use the leaflet in the application on vue 3.
Everything is working fine in development (npm run dev), but in production (npm run build), my app isn't able to locate the marker-icon.png and marker-shadow.png images.
In development:

In product:

How fix this problem?
Beta Was this translation helpful? Give feedback.
All reactions