Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom builds: problem to call the functions which are defined using a default export only #1478

Closed
LewisRob opened this issue Sep 5, 2018 · 2 comments

Comments

@LewisRob
Copy link

LewisRob commented Sep 5, 2018

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

@LewisRob
Copy link
Author

LewisRob commented Sep 6, 2018

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

@LewisRob LewisRob changed the title Custom builds: problem to call some the functions which are part of a module/package which contains a hyphen in their name Custom builds: problem to call the functions which are defined using a default export only Sep 6, 2018
@rowanwins
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants