无法从@ types / ol导入GeoJSON

时间:2019-10-23 07:34:40

标签: typescript openlayers geojson

我有以下文件:

tsconfig.json

{
    "compilerOptions": {
        "lib": [
            "es2019",
            "dom"
        ],
        "target": "es5",
        "module": "system",
        "allowSyntheticDefaultImports": true,
        "esModuleInterop": true,
        "outFile": "bundle.js"
    },
    "files": ["index.ts"]
}

Package.json

{
  "name": "testol",
  "version": "1.0.0",
  "description": "",
  "main": "bundle.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ol": "^5.3.3",
    "@types/ol": "^5.3.6"
  },
  "devDependencies": {
    "typescript": "^3.6.4"
  }
}

index.ts

import GeoJSON from 'ol/format/GeoJSON';
const geoJSON = new GeoJSON();

我运行tsc --build tsconfig.json时遇到很多错误,例如

node_modules/@types/ol/format/GeoJSON.d.ts:1:10 - error TS2305: Module '"node_modules/@types/ol/format/GeoJSON"' has no exported member 'Feature'.
1 import { Feature, FeatureCollection, GeoJSON as GeoJSON_1, Geometry, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon } from 'geojson';
           ~~~~~~~

node_modules/@types/ol/format/GeoJSON.d.ts:1:19 - error TS2305: Module '"node_modules/@types/ol/format/GeoJSON"' has no exported member 'FeatureCollection'.
1 import { Feature, FeatureCollection, GeoJSON as GeoJSON_1, Geometry, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon } from 'geojson';
                    ~~~~~~~~~~~~~~~~~

这是怎么了? 我已尝试按照建议的here

安装@ types / geojson的旧版本

1 个答案:

答案 0 :(得分:0)

我设法通过

使它运行
{
    "compilerOptions": {
        "target": "es5",
        "module": "amd",
        "importHelpers": true,
        "declaration": false,
        "moduleResolution": "node",
        "outFile": "bundle.js"
    },
    "files": ["index.ts"]
}