打字稿错误,找不到名称'gapi',转换失败 [英] Typescript Error, Cannot find name 'gapi', transpile failed
问题描述
我尝试在我的ionic2应用中实现google auth。我需要它在浏览器中工作。所以,我安装了:
I trying to implement google auth in my ionic2 app. I need it works in browser. So, I installed:
npm install --save @types/gapi
npm install --save @types/gapi.auth2
有两个警告:
npm WARN可选SKIPPING OPTIONAL DEPENDENCY:fsevents@^1.0.0
(node_modules\chokidar\\\
ode_modules\fsevents):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup
跳过可选的依赖性:不支持的
fsevents@1.0.15平台:想要{os:darwin,arch:any}(当前:
{os:win32,arch:x64})
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.0.15: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
在node_modules文件夹中我有gapi和gapi.auth2文件夹,但我有打字稿错误:找不到名称'gapi',转换失败。
In node_modules folder I have gapi and gapi.auth2 folders but I have typescript error: Cannot find name 'gapi', transpile failed.
我安装了
npm install typings -g
typings install dt~gapi --global --save
typings install dt~gapi.auth2 --global --save
仍然有同样的错误:找不到名字'gapi',transile f ailed
Still have the same error: Cannot find name 'gapi', transpile failed
我的代码:
auth2: any;
login() {
gapi.load('auth2', () => {
this.auth2 = gapi.auth2.init({
client_id: 'xxxxxxxxx.apps.googleusercontent.com',
scope: 'https://www.googleapis.com/auth/userinfo.email'
});
});
};
my package.json:
my package.json:
"@angular/core": "2.2.1",
"ionic-angular": "2.0.0-rc.4",
"ionic-native": "2.2.11",
"rxjs": "5.0.0-beta.12",
"typescript": "2.0.9"
推荐答案
gapi
的当前声明和 for gapi.auth2
是全局声明。
The current declarations for gapi
and for gapi.auth2
are global declarations.
它们可能不会自动与 @types
一起使用,因为查看 node_modules
要么显示 import
,要么将库添加到 types
字段> tsconfig.json 。
They might not be automatically with @types
because looking into node_modules
either requires an explicit import
or adding your libraries to the types
field in your tsconfig.json
.
所以尝试将以下 types
字段修复到 compilerOptions
:
So try fixing up the following types
field to your compilerOptions
:
"compilerOptions": {
"types": ["gapi", "gapi.auth2"]
}
这篇关于打字稿错误,找不到名称'gapi',转换失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!