turf.js error - turf.distance is not a function ERROR

Created on 18 Apr 2017  路  3Comments  路  Source: Turfjs/turf

I am using turf.js for the first time utilising its distance function part of @turf/distance module and when I run my server I get the issue saying, 'turf.distance' is not a function.
This is the code that generates the error.

https://jsfiddle.net/tcudrp7u/

Error show in Terminal

https://jsfiddle.net/Lu0db0m5/

All 3 comments

Gday @privateOmega

Because you're pulling in @turf/distance as a standalone module there is no global variable called turf

So you simply need to do something like
const distance= require('@turf/distance'); var from = { "type": "Feature", "properties": {}, "geometry": { "type": "Point", "coordinates": [-75.343, 39.984] } }; var to = { "type": "Feature", "properties": {}, "geometry": { "type": "Point", "coordinates": [-75.534, 39.123] } }; var units = "miles"; var distance = distance(from, to, units);
Hope that helps

@rowanwins thanks a lot for the solution. It worked perfectly.

Still getting same error

Was this page helpful?
0 / 5 - 0 ratings