Angular 6 - @types/googlemaps/index.d.ts' is not a module
For Angular6~
npm install @types/googlemaps --save-dev
oryarn add @types/googlemaps
- Add
"googlemaps"
totsconfig.app.json
types array
- Add
"googlemaps"
totsconfig.spec.json
types array
- Add
/// <reference types="@types/googlemaps" />
on the first line of your component.ts file. This line will import @types/googlemaps. (Line1 of example below) - Declare google variable as
declare let google: any;
(Line6 of example below)
Ref:
- https://stackoverflow.com/a/52200117/10009565
You probably don't need this line in your component.ts file (It's only for Angular <6):
import { } from '@types/googlemaps';
Here's an (basic/minimal) example for Angular 6:
/// <reference types="@types/googlemaps" />
map: google.maps.Map;
this.map = new google.maps.Map(....);
Basically, if you want to use it in Angular <6, you have to add it via the import
method. In Angular 6+ you have to add it via the reference
method. You shouldn't add both at the same time.
Hope I could help.