3

How can I import the "geojson" package into my Angular 6 project?

I previously had the following in my Angular 5.2 project.

import GeoJson = require("geojson");
import WKT = require("terraformer-wkt-parser");

I've since upgraded to Angular 6 and now I get runtime error:

error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.

So I checked out this SO Question . That doesn't appear to work since the values now have certain values.

So I then tried:

import GeoJson from "geojson";

But I still get runtime error:

Module '"C:/Dev/MyProject/ClientApp/node_modules/@types/geojson/index"' has no default export.

EDIT: Reformatted so that import line stood out.

qaisjp
  • 722
  • 8
  • 31
PrivateJoker
  • 781
  • 4
  • 13
  • 27

2 Answers2

3

import * as GeoJson from 'path'

Taranjit Kang
  • 2,510
  • 3
  • 20
  • 40
2

With

import GeoJson from "geojson";

You are looking for a module with the name "GeoJson" this is only correct if you are importing an exported library as a module

As apparently, it is not the case, you must import all the contents of the library (*) as if it were a module

import * as GeoJson from 'geojson'
Daniel
  • 951
  • 7
  • 20