Search code examples
javascriptreactjsreact-nativeturfjs

How to import turf modules properly


This should be straigh forward.

yarn add turf

and then - according to documentation:

// Import your module of interest
var collect = require('@turf/collect');
// or in ES6
import collect from '@turf/collect';

But, when I try any of these, it does not work. I get

Unable to resolve module @turf/collect.

When I check the node_modules folder, I see that turf installed properly (at least there are folders and there is something in them).

node modules folder

I tried this in a react-native project:

  1. watchman watch-del-all
  2. Delete node_modules and freshly yarn install
  3. Reset Metro's cache with yarn start --reset-cache

Solution

  • The namespace changed. Turf must be installed with @turf/turf, i.e. yarn add @turf/turf