leaflet.css and webpack css-loader
See original GitHub issueIn the commit https://github.com/Leaflet/Leaflet/commit/e9957cfa02b4201c62e98d43acc23acd5f3f9927 there is the following change:
+.leaflet-default-icon-path {
+ background-image: url(images/);
+ }
But now, in webpack with the css-loader I get the following error:
ERROR in ./~/css-loader!./~/leaflet/dist/leaflet.css
Module not found: Error: Cannot resolve directory './images' in /Users/jmlopez/Workspace/ProjectName/node_modules/leaflet/dist
@ ./~/css-loader!./~/leaflet/dist/leaflet.css 6:8715-8735
If I make it a proper url to a file then the compilation goes through. Anyone else having this issue? Should I bring this up with https://github.com/webpack/css-loader?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:17
- Comments:40 (15 by maintainers)
Top Results From Across the Web
How to include "leaflet.css" in a React app with webpack?
I solved it by simply importing the CSS like this: import 'leaflet/dist/leaflet.css';.
Read more >Essential setup steps to use React-Leaflet - ZQ.Yu
Install related packages; Import Leaflet CSS ... You don't need to worry about Leaflet JS file as the webpack will bundle the JS...
Read more >Download - Leaflet - a JavaScript library for interactive maps
images - This is a folder that contains images referenced by leaflet.css . It must be in the same directory as leaflet.css ....
Read more >Webpack leaflet configuration – Ganesh Kumar R
Installation: npm install leaflet webpack.config.js resolve: { alias: { ". ... use: [ MiniCssExtractPlugin.loader,'css-loader','sass-loader' ] ...
Read more >How to include "leaflet.css" in a React app with webpack?
The most commonly used CSS loader is webpack/css-loader. I disagree with the answer from Lakshman Diwaakar in that I think it is extremely...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone else landing here and struggling with this, the following webpack2
resolve.alias
configuration should enable you to import the leaflet.css regardless of whether you’re using CSS modules or not:n.b the actual path to the images may differ depending on where your webpack config file is in relation to node_modules
I think the problem that brought me here is the same. Here is my solution without the need of a workaround.
Obs.: When I started having these errors, I was using
html-loader
andcss-loader
, among others for js and json.Running leaflet with webpack was throwing an error about the .PNG images addresses from leaflet.css. I understood that It was trying to load the images as a CSS. So, the main question was how to provide a file loader in webpack that can read the .PNG files.
There is a package (file-loader) that solved this in a simple way. Below is how I used it:
Packages:
In
weback.conf.js
file, I included this code: