Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 710
kainos90 Avatar asked Jan 31 '19 20:01

kainos90


1 Answers

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

like image 69
sgimeno Avatar answered Nov 15 '22 04:11

sgimeno