类型 googlemaps index.d.ts 不是模块错误消息

Posted

技术标签:

【中文标题】类型 googlemaps index.d.ts 不是模块错误消息【英文标题】:types googlemaps index.d.ts is not a module error message 【发布时间】:2019-08-31 10:25:59 【问题描述】:

我似乎无法解决此错误,尝试在我的应用中实现 google 自动完成以进行地点搜索。

我已经尝试了大多数在线建议来解决此问题 打字安装 dt~google.maps --global npm install typings --global npm install @types/googlemaps --save-dev npm install @agm/core --save npm install ngx-google-places-autocomplete npm i -S google-places-autocomplete-service npm install @google/maps

我最初收到此错误: 无法导入类型声明文件。考虑导入“googlemaps”而不是“@types/googlemaps”。

然后在导入 googlemaps 后出现以下错误: node_modules/@types/googlemaps/index.d.ts' 不是模块。

奇怪的是在我的打字 -> 全局 -> google.maps -> index.d.ts 文件导出类 Map 有一个错误,指出存在重复的标识符。

我检查了,该命名空间也在 node_modules -> @types -> googlemaps -> index.d.ts 中。

所以看起来命名空间是在多个文件中声明的。我不确定它应该在哪里。

【问题讨论】:

【参考方案1】:

我卸载了所有东西并使用了以下代码......更简单。

我只需要安装 ngx-google-places-autocomplete

  public handleCityChange(cities: any) 
    this.location = cities.formatted_address;
    console.log('location', this.location);
  
                <input ngx-google-places-autocomplete [options]='options' #placesRef="ngx-places" (onAddressChange)="handleDesiredCityChange($event)"/>

【讨论】:

以上是关于类型 googlemaps index.d.ts 不是模块错误消息的主要内容,如果未能解决你的问题,请参考以下文章

tslint:禁用在 vscode 中不起作用

如何在 index.d.ts 打字稿定义文件中引用 Redux 类型?

从 typescript 模块自动生成 index.d.ts,类型定义

在 Visual Studio 代码中,如何跳转到 typescript 类型定义 index.d.ts 中的实际代码?

解决 npm 包提供的错误 index.d.ts 文件

Angular Library 11:在构建中包含 index.d.ts