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 폴더가 있지만 타이프 라이터 오류가 있습니다 : 이름 'GAPI'을 찾을 수 없습니다, transpile 실패

이 경고
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 gapifor gapi.auth2은 전역 선언입니다. node_modules를 조사 중 명시 적 import을 필요로하거나 tsconfig.jsontypes 필드에 라이브러리를 추가하기 때문에

그들은 @types 자동으로되지 않을 수 있습니다.

그래서 당신 compilerOptions에 다음 types 필드를 고정하려고 :

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

덕분에 나를 위해 일한! 최신 버전의 angular-cli에서는이 편집을위한 올바른 파일이 tsconfig.app.json 일 수 있습니다 – Willy