我正在尝试将 Firebase Remote Config 集成到我的 Cordova 应用程序中,以强制用户在拥有最低版本时进行更新,但导入包会导致错误。它不能在代码中,因为错误是在代码运行之前抛出的,只是通过导入包。
TypeError: Expected `input` to be a `Function` or `Object`, got `undefined`
at ./node_modules/gtoken/node_modules/pify/index.js.module.exports (index.js:45)
at Object../node_modules/gtoken/build/src/index.js (index.js:22)
我完全复制并粘贴了 Google 教程中的代码,但出现了错误。我在 sandbox.io 上创建了一个私有(private) React 沙箱,一切都运行良好,所以我知道我在 Firebase 上正确设置了所有配置,这不是身份验证的问题。
我试过从字面上删除所有代码并只导入包 import { google } from 'googleapis';
但我收到错误,所以我不知所措。
我尝试卸载并重新安装 npm 包——不行。
我卸载了 googleapis
包并安装了它使用的 google-auth-library
。同样的问题。
我卸载了它并安装了 gtoken
库。同样的问题。
有人有什么想法吗?
最佳答案
这是因为 gtoken npm 包(依赖于 googleapis)正在使用 NodeJS“fs”API 从文件系统读取证书,而“fs”API 在浏览器中不可用。
在 node_modules/gtoken/build/src/index.js 第 21 行
var readFile = pify(fs.readFile); // fs.readFile is undefined in a browser context
在浏览器中使用 Google APIs 的首选包是 Google APIs Javascript Client 而不是 npm googleapis one。参见 https://developers.google.com/api-client-library/javascript/start/start-js
关于javascript - 是什么导致 TypeError : Expected `input` to be a `Function` or `Object` issue with gtoken and pify?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54468809/