What is the problem of icon loading error when using leaflet in webpack?

1 when adding marker using leaflet in webpack, use the default marker to report an error

the default marker name will be added to the transcoded base64 icon

related configurations in webpack.config.js

resolve: {
      alias: {
          "@":path.resolve(__dirname, "./src"),
          leaflet_css: __dirname + "/node_modules/leaflet/dist/leaflet.css",
          leaflet_marker: __dirname + "/node_modules/leaflet/dist/images/marker-icon.png",
          leaflet_marker_2x: __dirname + "/node_modules/leaflet/dist/images/marker-icon-2x.png",
          leaflet_marker_shadow: __dirname + "/node_modules/leaflet/dist/images/marker-shadow.png",
      }
  },

Code

import "leaflet_css"; 
import L from "leaflet";

(function(){
    var map = L.map("map-osm-leaflet").setView([51.505, -0.09], 13);

    L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
        attribution: " <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors"
    }).addTo(map);

    L.marker([51.5, -0.09]).addTo(map)
        .bindPopup("A pretty CSS3 popup.<br> Easily customizable.")
        .openPopup();
})();

the icon is passed in by yourself. You can use it normally if you don't use the default icon.

(function(){
     var myIcon = L.icon({
         iconUrl: marker_icon,
         iconSize: [20, 20],
         iconAnchor: [10, 20],
    });

    var map = L.map('map-osm-leaflet').setView([51.505, -0.09], 13);

    L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        attribution: ' <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
    }).addTo(map);

    L.marker([51.5, -0.09],{
        icon: myIcon
    }).addTo(map)
        
})();

that's the problem for me, too. The default icon in my project can't use the same error. I don't know why it becomes base64, in my project, but it becomes cdn, on the official website

.

the later solution is to manually introduce leaflet icons

import icon from "leaflet/dist/images/marker-icon.png";
import iconShadow from "leaflet/dist/images/marker-shadow.png";

let DefaultIcon = L.icon({
            iconUrl: icon,
            shadowUrl: iconShadow
        });
L.Marker.prototype.options.icon = DefaultIcon;
new L.marker(//marker).addTo(this.map); 
Menu