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);

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.

  • Ok, it's good at least to have it confirmed that I am not going mad. I think I shall trash node_modules and do a fresh npm install and see if that helps – mwarren Mar 2 '18 at 23:17
  • 1
    I've updated my question with the solution. I've given you the answer because your confirmation that I wasn't doing anything wrong with the import helped a lot. – mwarren Mar 2 '18 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.