What is causing TypeError: Expected `input` to be a `Function` or `Object` issue with gtoken and pify?
Asked Answered
C

1

7

I'm trying to integrate Firebase Remote Config into my Cordova application to force users to update if they have a minimum version, but importing the package causes an error. It can't be in the code, because the error is thrown before the code runs just by importing the package.

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)

I've literally copied and pasted the code from the Google tutorial and I get the error. I created a private React sandbox on sandbox.io and everything worked perfectly, so I know that I have all the configuration set up on Firebase correctly and it's not an issue with authentication.

I've tried literally deleting all the code and just importing the package import { google } from 'googleapis'; and I get the error, so I'm at a loss.

I tried uninstalling and reinstalling the npm package -- no dice.

I uninstalled the googleapis package and installed the google-auth-library that it uses. Same problem.

I uninstalled that and installed the gtoken library. Same issue.

Anyone have any ideas?

Cooperstein answered 31/1, 2019 at 20:33 Comment(3)
Created an issue in github: github.com/googleapis/google-api-nodejs-client/issues/1614Stouffer
The issue was marked as bug. I hope they do a fix soon.Stouffer
We are stuck here, I have the same problem in reactTypeset
U
1

This is due to the fact that gtoken npm package (dependecy of googleapis) is using NodeJS "fs" API to read certificates from the filesystem and "fs" API is not available in the browser.

in node_modules/gtoken/build/src/index.js Line 21

var readFile = pify(fs.readFile); // fs.readFile is undefined in a browser context

Preferred package to use Google APIs in the browser is Google APIs Javascript Client instead of npm googleapis one. See https://developers.google.com/api-client-library/javascript/start/start-js

Underestimate answered 7/4, 2019 at 10:4 Comment(1)
IMO, the biggest downside to using the browser JavaScript client is the lack of type safety in TypeScript projects.Sthilaire

© 2022 - 2024 — McMap. All rights reserved.