TypeScript Error: Cannot find namespace 'google'

后端 未结 7 631
青春惊慌失措
青春惊慌失措 2021-01-12 06:33

I have project angular-cli

~root~/src/typings.json

{
  \"globalDevDependencies\": {
    \"angular-protractor\": \"registry:dt/angula         


        
相关标签:
7条回答
  • 2021-01-12 07:11

    In IONIC 4 I fixed it by installing @types/google-maps not @types/googlemaps

    just run this

    npm install @types/google-maps --save
    

    and import google in your component using

    import { google } from "google-maps";
    
    0 讨论(0)
  • 2021-01-12 07:20

    Try to run the below command in a node prompt...

    typings install dt~google.maps --global --save
    
    0 讨论(0)
  • 2021-01-12 07:27

    I had the same problem with angular 7. I did not need to import anything just run npm install @types/googlemaps again and if there is any vulnerabilities, run npm audit fix or npm audit fix --force if needed.

    After I did so, everything worked fine for me...

    0 讨论(0)
  • 2021-01-12 07:33

    A bit of a late response but I had a similar issue using Angular CLI RC.0.

    It turned out that I hadn't install and imported the typings, which can be done as follows:

    npm install --save-dev @types/googlemaps
    
    import {} from '@types/googlemaps';
    
    0 讨论(0)
  • 2021-01-12 07:36

    For anyone in Vue js facing this issue, you can add the following line at the top of your script section. Make sure you have installed @types/googlemaps.

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

    0 讨论(0)
  • 2021-01-12 07:37

    For Angular 9.****

    I tried installing @types/googlemaps, It did not work for me.

    I downgrade it to "@types/googlemaps": "3.39.12" then worked perfectly fine.

    this is my code

    In tsconfig.app.json (add googlemaps to types array)

    "types": [
          "googlemaps"
        ]
    

    In app module.ts

    import { AgmCoreModule } from '@agm/core';
    .
    .
    .
    .
     imports: [
        BrowserModule,
        AppRoutingModule,
        AgmCoreModule.forRoot({
          apiKey: '...KEY...',
          libraries: ['places']
        })
      ],
    

    To downgrade @types/googlemaps, go to pakage.json file in the project root folder and change @types/googlemaps version to "3.39.12". it's better if you delete files form

    node_module -> @types -> googlemaps
    

    Then in the terminal enter

    npm install
    
    0 讨论(0)
提交回复
热议问题