@types/googlemaps/index.d.ts' is not a module

房东的猫 提交于 2019-11-27 18:17:55

Thanks to this documentation link : https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html

[Angular 6+] You only have to add this line at the beginning (meaning line 1, with nothing before) of your Typescript file :

/// <reference types="@types/googlemaps" />

[Angular 5-] You only have to add this line anywhere in your Typescript file imports :

import {} from "googlemaps";

Thanks to the answer below, you may also need to add a file <root>/index.d.ts containing (didn't need it though in my case) :

declare module 'googlemaps';

The import can be simplified as follows:

import {} from "googlemaps";

Add a file at your projects root directory named index.d.ts and paste the following:

declare module 'googlemaps';

I just created a index.d.ts in my src folder and added

declare module 'googlemaps';

It solved the issue

For me in Angular 6, it worked when I only used

/// <reference types="@types/googlemaps" />
Raghulraj Palanisamy

It works fine

npm install --save-dev @types/googlemaps
At the beggining of your component file, type:
/// <reference types="@types/googlemaps" />

In my angular 6+ project I've solved the problem declaring the googlemaps namespace in the top of the typescript file with this line:

/// <reference path="../../../../../../node_modules/@types/googlemaps/index.d.ts"/>

with this done you must not import googlemaps in other ways and then it works. Use the correct path to your node_modules folder.

For further information and references about namespace usage in Typescript here the documentation.

In my Angular 7+ project

$ npm install @types/googlemaps --save-dev
In tsconfig.app.json

"types": [
      "googlemaps"
]

Thank you the link below https://www.freakyjolly.com/angular-7-6-add-google-maps-in-angular-2-plus-applications-using-angular-google-maps-module-agm-core-easily/#more-2316

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!