1

i'm trying to import a .geojson file in React using:

import data from 'filename.geojson';

but when i print the following code console.log(data) to check if it was load, i got this:

/static/media/filename.e789b00e.geojson

Then, if i change the file extension to .json instead of .geojson, it loads the geoJSON object properly. What's the problem?

I'm trying to use the geojson object in react-leaflet <GeoJSON />

1 Answer 1

0

It's possible that webpack is using different import policies for .json files and .geojson files.

Look here: https://v4.webpack.js.org/loaders/json-loader/

If you need to handle custom extensions as json, you need to specify it so that the json-loader is used for them too.

edit: updated link, thanks to NanoNova!

1
  • I think the link moved to here
    – NanoNova
    Sep 17, 2020 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.