1

I'm using Mapbox, and I'm trying to convert a Geojson to a zipped shapefile using shp-write. But when I follow the example given on the GitHub page, I'm getting a "ReferenceError: require is not defined" error on this line:

var shpwrite = require('shp-write');

This is a jsfiddle in which you can test this. I'm relatively new to JavaScript, and haven't had to use the 'require()' function before.

halfer
  • 19,824
  • 17
  • 99
  • 186
Raj
  • 315
  • 4
  • 15

1 Answers1

1

The jsfiddle you provided includes several external resources, among which a shpwrite delivered by unpkg that you may be missing.

Usually require doesn't exist in your browser. You would need to execute it with Node.js or use a module bundler like Webpack, but Unpkg takes care of it for you.

So adding:

<script src="https://unpkg.com/shp-write@latest/shpwrite.js"></script>

on your page should make it work.

MeltedPenguin
  • 787
  • 7
  • 17
  • Thank you so much for your quick response. So you mean that in the case of this jsfiddle, since I've already added that unpkg link for shp-write under External Resources, I can just remove the entire "var shpwrite = require('shp-write');" line and it should work? I did that in this [jsfiddle](https://jsfiddle.net/rajkishan16/3xff9zmy/1/) and got an error "Error: This method has been removed in JSZip 3.0, please check the upgrade guide". Is that a separate issue? – Raj Jan 18 '18 at 17:46
  • 1
    There is an issue about this error on the shpwrite Github page. You should try the solution in the last comment until they fix it https://github.com/mapbox/shp-write/issues/48 – MeltedPenguin Jan 19 '18 at 18:18
  • I noticed that issue as well and used the workaround given in the solution, and now it works! So thanks a lot for your help. – Raj Jan 19 '18 at 20:07