2

私のionic2アプリでgoogle認証を実装しようとしています。私はそれがブラウザで動作する必要があります。だから、私はインストール:Typescriptエラー、名前 'gapi'が見つかりませんでした、transpileが失敗しました

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected]^1.0.0 (node_modules\chokidar\node_modules\fsevents):

npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

node_modulesフォルダで私はGAPIとgapi.auth2フォルダを持っているが、私はtypescriptですエラーがあります:名 'GAPI' を見つけることができません、transpile失敗

2つの警告
npm install --save @types/gapi 
npm install --save @types/gapi.auth2 

あり。

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' 
      }); 
     }); 
     }; 

私のpackage.json:

transpileが

私のコードを失敗した、名 'GAPI' を見つけることができません:

は、私はまだ同じエラーを持っている

npm install typings -g 
typings install dt~gapi --global --save 
typings install dt~gapi.auth2 --global --save 

をインストール
"@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" 

答えて

4

The current declarations for gapiおよびfor gapi.auth2はグローバル宣言です。 node_modulesに探して、明示的なimportを必要としたり、tsconfig.jsontypesフィールドに自分のライブラリを追加するため

彼らは@typesで自動的にではないかもしれません。

だからあなたcompilerOptionsに次のtypesフィールドを固定してみてください。

"compilerOptions": { 
    "types": ["gapi", "gapi.auth2"] 
} 
+0

おかげで、私のために働きました! 新しいバージョンのangular-cliでは、これらの編集用の正しいファイルはtsconfig.app.json – Willy

関連する問題