I've been using various Turf packages in my React Native app for awhile now without problem. However, when attempting to update my Turf packages to use Turf v3.5.2, now using import turf from '@turf/turf', I get the following error message:
babelHelpers.typeof is not a function. (In 'babelHelpers.typeof(exports)'; 'babelHelpers.typeof' is undefined)
The problem is that the jsts library has a .babelrc file specifying the "es2015" preset. This preset is known to not work with React Native. If I update the .babelrc inside the jsts package to specify "es2016", it works. I'm thinking about making a PR to the jsts library to handle this, but I'd be surprised if others haven't run into this issue, and I'm not sure if this is the proper way to handle this. Has anyone else run into this problem using Turf with React Native, and if so how was it resolved?
Actually, it turns out that just removing the .babelrc file from jsts solves it as well. I think the fix is to just not include the .babelrc file when publishing the package. I filed an issue in jsts here.
You should also consider using the namespaces (ex: @turf/point or @turf/buffer) instead of the global @turf/turf library. Depending on the type of library you need from Turf, you might not even need jsts as a dependency.
Thanks. For my case the global @turf/turf library is ideal since I'm using at least 10 of the sub packages. For now I've added a postinstall script to my package.json to remove the .babelrc file from jsts.
Looks like when jsts 1.2.2 is out, we can upgrade and this issue will be resolved.