tyrasd / osmtogeojson

convert osm to geojson
http://tyrasd.github.io/osmtogeojson/
MIT License
694 stars 113 forks source link

__webpack_require__(...).forEach is not a function #56

Closed spaasis closed 8 years ago

spaasis commented 8 years ago

Hi,

I'm trying to get osm conversion to work, but I get the above error message with let osmtogeojson = require('osmtogeojson');

I also tried let osmtogeojson = require('osmtogeojson').default; and to use babel-plugin-add-module-exports as per this SO thread, but nothing seems to work.

Any further ideas on how to get this working? I'll happily provide more details

tyrasd commented 8 years ago

Hi. Hmm. Does it work if you explicitly use version 2.2.8 of osmtogeojson?

spaasis commented 8 years ago

Uh, not exactly.. When I run webpack, there's a new error:

ERROR in ./~/osmtogeojson/polygon_features.json Module parse failed: /projectpath/node_modules/osmtogeojson/polygon_features.json Unexpected token (2:14) You may need an appropriate loader to handle this file type. SyntaxError: Unexpected token (2:14) at Parser.pp$4.raise

tyrasd commented 8 years ago

Oh, I see what's going on: By default, webpack can't (or won't) require in raw json files (which is done by the osm-polygon-features dependency of osmtogeojson).

If you add a json-loader to your webpack config (e.g. { test: /\.json$/, loader: 'json-loader' },), it should work fine.

tyrasd commented 8 years ago

It's not a bug on osmtogeojson's side. I'm not sure why webpack differs from the way node handles required json files, but I guess it's a deliberate thing. :confused:

spaasis commented 8 years ago

Thanks a lot, everything (including the new version, for whatever reason..) seems to work now!