问题描述
我正在尝试在NodeJS
应用程序中加载名为'geojson2h3'的程序包。运行npm install geojson2h3
之后,我尝试按照Github
中给出的初始代码说明进行测试:
import geojson2h3 from 'geojson2h3';
const polygon = {
type: 'Feature',geometry: {
type: 'polygon',coordinates: [
[
[-122.47485823276713,37.85878356045377],[-122.47504834087829,37.86196795698972],[-122.47845104316997,37.86010614563313],[-122.47485823276713,37.85878356045377]
]
]
}
};
const hexagons = geojson2h3.featuretoH3Set(polygon,10);
// -> ['8a2830855047fff','8a2830855077fff','8a283085505ffff','8a283085506ffff']
const feature = geojson2h3.h3SetToFeature(hexagons);
// -> {type: 'Feature',properties: {},geometry: {type: 'polygon',coordinates: [...]}}
当然,这会引发SyntaxError: Cannot use import statement outside a module
错误。然后,我尝试使用NodeJS require
这样的方法:const geojson2h3 = require('geojson2h3');
,替换了import
语句。这将引发Uncaught Error: undefinedModule
错误。该软件包显示在我的package.json
文件中,但是在我的node_modules
文件夹中看不到它。我假设这与问题有关。我在这里做错了什么?
*注意:我知道这是一个与GIS相关的软件包,但问题是一个通用的NodeJS软件包问题,而不是特定于GIS的软件包。