【问题标题】:Cannot find namespace 'google' in ionic 3 app在 ionic 3 应用程序中找不到命名空间“google”
【发布时间】:2018-02-26 02:47:51
【问题描述】:

在我尝试在我的项目中使用 google 变量后,我在 ionic 3 应用程序中遇到了这个错误,谁能帮我解决这个错误,

npm install --save @types/google-maps

在我的 package.json 中添加了以下内容:

"@types/google-maps": "^3.2.0",

我也确实声明了 declare var google;

然后typings install dt~google.maps --global

然后我看到了这个灵魂并尝试了它,但也没有用(注意我生成了一个 ios 密钥和 android 密钥) 试过这个 Cannot find namespace 'google'

离子科尔多瓦插件添加 https://github.com/mapsplugin/cordova-plugin-googlemaps#multiple_maps --variable API_KEY_FOR_ANDROID="YOUR_ANDROID_API_KEY_IS_HERE" --variable API_KEY_FOR_IOS="YOUR_IOS_API_KEY_IS_HERE" $ npm install --save @ionic-native/google-maps

我的 map.ts 的要点就是拍摄这个错误:

https://gist.github.com/abdulfatah-ah1407281/25bc95352d0b1ba8e02b7d1e55cc7779

运行 ionic serve 时出错:

Cannot find namespace 'google'.
C:/Users/pkhon/Desktop/k/ItBroken/src/components/map/map.ts
private map: google.maps.Map;
public isMapIdle:boolean;

【问题讨论】:

    标签: typescript ionic-framework ionic2 ionic3


    【解决方案1】:

    你没有提到它,但我猜你是在 Windows 上。您正在使用 ionic,并且在某些情况下存在平台差异(不确定谁负责,离子或打字稿),其中相同的 tsconfig.json 文件将在 macos(可能还有 linux)上运行,但在 windows 中不显式添加typeRoots 进入你的compilerOptionstsconfig.json,像这样:

    // tsconfig.json
    {
      "compilerOptions": {
        // ... other stuff
        "typeRoots": [ 'node_modules/@types' ]
      }
      // ... other stuff
    }
    

    【讨论】:

      猜你喜欢
      • 2019-01-11
      • 2019-06-18
      • 2021-03-14
      • 2017-04-20
      • 2017-07-12
      • 1970-01-01
      • 1970-01-01
      • 2018-01-01
      • 1970-01-01
      相关资源
      最近更新 更多