在离子3应用程序中找不到命名空间'google' [英] Cannot find namespace 'google' in ionic 3 app

查看:138
本文介绍了在离子3应用程序中找不到命名空间'google'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我尝试在我的项目中使用google变量之后,任何人都可以帮我解决这个错误。


npm install --save @ types / google-maps


将以下内容添加到我的package.json中:


@ types / google-maps:^ 3.2.0,


我也声明了声明var google;



并且做了 typings install dt~google.maps --global



然后我看到了这个灵魂并尝试了但是这也没有用(注意我生成了一个ios密钥和android密钥)
试过这个
无法找到命名空间'google'


离子cordova插件添加
https ://github.com/mapsplugin/cordov a-plugin-googlemaps#multiple_maps
- 变量API_KEY_FOR_ANDROID =YOUR_ANDROID_API_KEY_IS_HERE - 变量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



运行离子服务时出错:

 无法找到命名空间'google'。 
C:/Users/pkhon/Desktop/k/ItBroken/src/components/map/map.ts
私人地图:google.maps.Map;
public isMapIdle:boolean;


解决方案

你没有提到它,但我是猜你是在Windows上。您正在使用离子,并且在某些情况下(不确定谁负责,离子或打字稿)存在平台差异,其中相同的 tsconfig.json 文件将在macos上工作(并且可能是Linux),但是没有明确地将 typeRoots 条目添加到<$ c $的 compilerOptions 中c> tsconfig.json ,如下所示:

  // tsconfig.json 
{
compilerOptions:{
// ...其他东西
typeRoots:['node_modules / @ types']
}
// ...其他东西
}


can anyone help me with this error im getting in my ionic 3 application after my attempt to use google variable in my project,

npm install --save @types/google-maps

which added the following to my package.json:

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

i also did declare declare var google;

and did typings install dt~google.maps --global

then i seen this soultion and tried it but that did not work either (notice i generated an ios key and android key) tried this Cannot find namespace 'google'

ionic cordova plugin add 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

gist for my map.ts thats shooting this error:

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

Error when i run 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;

解决方案

You didn't mention it, but I'm guessing you're on Windows. You're using ionic, and there's a platform difference under some circumstances (not sure who is responsible, ionic or typescript) where the same tsconfig.json file will work on macos (and maybe linux), but not in windows without explicitly adding a typeRoots entry to the compilerOptions of your tsconfig.json, like this:

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

这篇关于在离子3应用程序中找不到命名空间'google'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆