使用Create-react-app和googleapis时出现错误

6

我对React很陌生,所以我按照Heroku的指南使用Create-react-app创建了一个新的React应用程序。我想使用Google API通过Google的OAuth2认证用户并获取刷新令牌,因此我按照Google API Node Client的指南使用npm install googleapis --save安装了'googleapis'包,但是在我使用import {google} from 'googleapis'导入googleapis后,在我运行npm start时出现以下错误:

Uncaught TypeError: Cannot convert undefined or null to object
at Function.getPrototypeOf (<anonymous>)
at ./node_modules/google-p12-pem/node_modules/pify/index.js.module.exports (index.js:75)
at Object../node_modules/google-p12-pem/build/src/index.js (index.js:6)
at __webpack_require__ (bootstrap 8c14a9046e11e185076c:678)
at fn (bootstrap 8c14a9046e11e185076c:88)
at Object../node_modules/gtoken/build/src/index.js (index.js:50)
at __webpack_require__ (bootstrap 8c14a9046e11e185076c:678)
at fn (bootstrap 8c14a9046e11e185076c:88)
at Object../node_modules/google-auth-library/build/src/auth/jwtclient.js (jwtclient.js:63)
at __webpack_require__ (bootstrap 8c14a9046e11e185076c:678)
at fn (bootstrap 8c14a9046e11e185076c:88)
at Object../node_modules/google-auth-library/build/src/auth/googleauth.js (googleauth.js:60)
at __webpack_require__ (bootstrap 8c14a9046e11e185076c:678)
at fn (bootstrap 8c14a9046e11e185076c:88)
at Object../node_modules/google-auth-library/build/src/index.js (index.js:18)
at __webpack_require__ (bootstrap 8c14a9046e11e185076c:678)
at fn (bootstrap 8c14a9046e11e185076c:88)
at Object../node_modules/googleapis/build/src/lib/googleapis.js (googleapis.js:60)
at __webpack_require__ (bootstrap 8c14a9046e11e185076c:678)
at fn (bootstrap 8c14a9046e11e185076c:88)
at Object../node_modules/googleapis/build/src/index.js (index.js:18)
at __webpack_require__ (bootstrap 8c14a9046e11e185076c:678)
at fn (bootstrap 8c14a9046e11e185076c:88)
at Object../src/App.js (App.css?9a66:26)
at __webpack_require__ (bootstrap 8c14a9046e11e185076c:678)
at fn (bootstrap 8c14a9046e11e185076c:88)
at Object../src/index.js (index.css?f255:26)
at __webpack_require__ (bootstrap 8c14a9046e11e185076c:678)
at fn (bootstrap 8c14a9046e11e185076c:88)
at Object.0 (registerServiceWorker.js:117)
at __webpack_require__ (bootstrap 8c14a9046e11e185076c:678)
at ./node_modules/ansi-regex/index.js.module.exports (bootstrap 8c14a9046e11e185076c:724)
at bootstrap 8c14a9046e11e185076c:724

我错过了什么导致了这个错误?

这个问答对于让gapi在create-react-app/reactjs中工作起来很有帮助。https://dev59.com/WFcP5IYBdhLWcg3w3tqq - Donn Lee
我在 GitHub 上向 Google 提交了一个新问题,您可以在此处关注它:https://github.com/google/google-api-nodejs-client/issues/1027 - TacoEater
2个回答

6

3
这里的错误在于将其呈现在客户端上,而不是在服务器端上。 Googleapis库并不是用于在浏览器上运行,而是在您的节点应用程序服务器中运行。

这里是完整的答案(github)


这应该是被接受的答案。我一直在试图理解它。不幸的是,googleapis的创建者从未说过它是用于服务器端的。 - Radityo Ardi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接