Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type number #183

Closed
harvey56 opened this issue Sep 4, 2019 · 4 comments

Comments

@harvey56
Copy link

@harvey56 harvey56 commented Sep 4, 2019

Hello,

I'm trying to make requests to my firestore database in my lambda function.

I can declare a document reference as follows :
let userRef = db.collection('users').doc('hgyrirkignmght');
console.log("userRef: ", userRef); // this works

However, I cannot make a get() request :

userRef.get()
    .then(function(doc) {
      if (doc.exists) {
          console.log("Document data:", doc.data());
      } else {
          // doc.data() will be undefined in this case
          console.log("No such document!");
      }
    })
    .catch(function(error) {
        console.log("Error getting document:", error);
    });

This returns the error message as stated in the title :

Error getting document: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type number
    at validateString (internal/validators.js:125:11)
    at Object.dirname (path.js:1260:5)

I can't tell if the error is netlify related or firebase related.

I understand from this thread (#112) that there may be issues when making firebase requests using netlify-lambda. So, I tried netlify-dev as documented. I set it up (I have a .netlify folder in my server folder). I set the proxy target as http://localhost:34567. Now, if I go to http://localhost:34567/myfunction, I still have the same error message as with netlify-lambda.

Can we know for sure if the issue comes from netlify or firebase ? Any suggestion what can be done ?

I'm aware of an alternative way of using firebase (as documented here https://firebase.google.com/docs/projects/api/workflow_set-up-and-manage-project#before-you-begin). However, it's in beta and it doesn't work either. const resp = await rp(options); would return an empty object, although I do have projects (i.e. projects.length !== 0). But here again, the issue may be firebase related, I'm not sure.

Thanks for your kind help

@sw-yx

This comment has been minimized.

Copy link
Contributor

@sw-yx sw-yx commented Sep 4, 2019

first of all, can we make sure that you're hitting the right url. the function should be at http://localhost:34567/.netlify/functions/myfunction

to debug, i'd take a look at where that Object.dirname is being called. it takes a while but you'll know for sure.

i've had some success pinging firebase from netlify functions. i think whats happening in some of the other issues is problems bundling Firebase SDK because it includes native C++ modules.

@JeffML

This comment has been minimized.

Copy link

@JeffML JeffML commented Oct 8, 2019

The solution here worked for me, though I am still trying to figure out what my GOOGLE_APPLICATION_CREDENTIALS path variable should be: is it root? lambda folder? ./<path>, /<path>, or just <path>? Or do I set it in netlify.toml? or in my start command in package.json?

@sw-yx

This comment has been minimized.

Copy link
Contributor

@sw-yx sw-yx commented Oct 8, 2019

no idea. refer to their docs i guess. good luck

@sw-yx sw-yx closed this Oct 8, 2019
@frankcalise

This comment has been minimized.

Copy link

@frankcalise frankcalise commented Oct 30, 2019

Hey I can maybe help here. I just battled a bunch of firebase admin sdk + netlify function errors along the way, primarily because I wasn't too familiar with cloud functions.

For that error you're seeing about the first argument, may I ask what you're returning as the body to the response? It should be a string or if you want a JSON object, JSON.stringy it (or a buffer is allowed also).

Also the firebase app only wants to be initialized one time, so you can do something like this:

const admin = require("firebase-admin");
const serviceAccount = require("./firebase-dev.json");
console.log(admin.apps.length)
const app = !admin.apps.length
? admin.initializeApp({
    credential: admin.credential.cert(serviceAccount)
  })
: admin.app();


export default app

and then use it in your function js

import firebase from './utils/firebase'

exports.handler = async function(event) {
//...
  const querySnapshot = await firebase
    .firestore()
    .collection(`users`)
    .where("subscription_status", "==", "trialing")
    .get();
//return etc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.