简体   繁体   English

如何在Angular(v6)中导入

[英]How to import in Angular (v6)

How can I import the "geojson" package into my Angular 6 project? 如何将“ geojson”包导入到Angular 6项目中?

I previously had the following in my Angular 5.2 project. 我以前在Angular 5.2项目中拥有以下内容。

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

I've since upgraded to Angular 6 and now I get runtime error: 自从我升级到Angular 6之后,现在出现运行时错误:

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 . 所以我检查了这个SO问题 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. 编辑:重新格式化,以便进口线脱颖而出。

从'path'导入*作为GeoJson

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 您正在寻找名称为“ GeoJson”的模块,仅当您将导出的库作为模块导入时,这才是正确的

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'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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