[GIS] Turfjs default es6 import fails

javascriptmapbox-gl-js

I'm trying to use Turf distance and Turf point with Mapbox GL JS.

I've installed @turf/distance from npm which also installs @turf/helpers.

I see that distance has a default export

exports.default = distance;

So my import is as follows:

import distance from '@turf/distance';
import { point } from '@turf/helpers';

point imports as expected, distance is always empty, whatever I try.
This should be so simple….

Can anybody put me out of my misery, and tell me how they imported distance?

UPDATE: found the problem

I was reassigning the distance variable – what a noob.

let distance = distance(from, to, options);

Best Answer

I'm sorry to say that that should just work.

I have a project with Turf loaded, and just added:

import distance from '@turf/distance'

...

console.log("DISTANCE IS: ", distance)

And I get this logged on the console:

Distance function is logged

What this means is that it seems to work fine to import that way. Maybe check your code somewhere else.