Tag Archives: Omnipotent JavaScript

[Solved] Turf.js error: uncaught (in promise) error: the solution of invalid unit

Solution for turf.js error: Uncaught (in promise) Error: Invalid unit
Error code (npm i turf):

import turf from 'turf';

var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);
var options = {units: 'miles'};

var along = turf.along(line, 200, options); // Wrong

Correct code (NPMI @ turf/turf)

import * as turf from '@turf/turf';

var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);
var options = {units: 'miles'};

var along = turf.along(line, 200, options);