简体   繁体   English

如何正确导入草坪模块

[英]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项目中试过这个:

  1. watchman watch-del-all
  2. Delete node_modules and freshly yarn install删除node_modules并重新yarn install
  3. Reset Metro's cache with yarn start --reset-cacheyarn 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM