Hi,
Thanks for this great spatial library.
I never encountered any problem to build and to use some Turf custom builds before but it appears that a function appears has not defined if it is part of a module whose the name contains a hyphen, e.g. hex-grid (or any other *-grid), bbox-polygon, etc.
Here is a simple example based on npm runkit (here hex-grid):
var hexGrid = require("@turf/hex-grid")
var bbox = [-96,31,-84,40];
var cellSide = 50;
var options = {units: 'miles'};
var hexgrid = hexGrid(bbox, cellSide, options);
var addToMap = [hexgrid];
It appears that "hexGrid is not a function". The same problem when a custom build is created with only the hex-grid module in it.
Thanks for your support.
Lewis
Hi,
I managed to solve this problem by myself. Sorry to have created an issue about it.
The hexgrid function as well as some other ones are only exported using the default option, i.e. export default hexGrid. Therefore it needs to be called slightly differently as users of these different modules need to add "default" to access it, for example:
var hexGrid = require("@turf/hex-grid").default
Same thing in their Node configuration:
module.exports = {
hexGrid: require('@turf/hex-grid').default
};
It would maybe be good to add this use case in this part of the Turf documentation (Step 2) and to create a list somewhere to know which module relies only on the default export such as hex-grid, square-grid, bbox-polygon, etc.
Lewis
Hey @LewisRob
Yeah unfortunately there was a change to bundling in v6 which had some flow on impacts were which never got communicated via the docs. We're currently working on a bit of an overhaul for v7 which will then get fully documented.
Sorry for the hassle
Most helpful comment
Hi,
I managed to solve this problem by myself. Sorry to have created an issue about it.
The hexgrid function as well as some other ones are only exported using the default option, i.e.
export default hexGrid. Therefore it needs to be called slightly differently as users of these different modules need to add "default" to access it, for example:Same thing in their Node configuration:
It would maybe be good to add this use case in this part of the Turf documentation (Step 2) and to create a list somewhere to know which module relies only on the default export such as hex-grid, square-grid, bbox-polygon, etc.
Lewis