[英]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
.无法解析模块
@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
文件夹时,我看到turf
安装正确(至少有文件夹并且里面有东西)。
I tried this in a react-native
project:我在
react-native
项目中试过这个:
watchman watch-del-all
node_modules
and freshly yarn install
node_modules
并重新yarn install
yarn start --reset-cache
yarn start --reset-cache
重置 Metro 的缓存I was led to this question for a related problem.由于相关问题,我被带到了这个问题。
To import a specfic module with a name that is more than one word it becomes camel case like so:要导入名称超过一个单词的特定模块,它会变成驼峰式大小写,如下所示:
import nearestPointOnLine from '@turf/nearest-point-on-line';
import booleanPointInPolygon from '@turf/boolean-point-in-polygon';
The namespace changed.命名空间已更改。 Turf must be installed with
@turf/turf
, ie yarn add @turf/turf
Turf 必须与
@turf/turf
一起安装,即yarn add @turf/turf
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.