无法安装和使用 Turf.js

Unable to install and use Turf.js

我想使用 booleanCrosses and booleanContains methods from Turf.js library in my application on the client side, but I fail. I first tried to download just turf.min.js,但是在我的代码中调用 turf.booleanContains(...) 时,我得到

TypeError: turf.booleanContains is not a function

我还尝试下载整个 turf 存档并使用 npm 安装所需的包,但收到了一大堆错误消息。那么,安装 turf.js 和一些特定软件包的正确方法是什么?

我遇到了这个问题并使用 yarn 解决了这个问题。我的 node_modules 中有一块陈旧的地盘 index.d.ts(不清楚为什么)。我希望我能准确地记住我做了什么,但编辑 package.json(我把它们打乱是为了刺激纱线——尽管那可能什么也没做)

"@turf/boolean-contains": "^4.6.1",
"@turf/turf": "^4.6.1",

然后 运行 yarn(yarn 是 npm 的更精简、更精简的替代品 install/update - 通过 npm i -g yarn 安装并享受)

现在 index.d.ts 显示附加模块(包括 booleanContains,这是我的特定问题)。

像这样导入模块:

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

并按文档使用。