1

I'm using firebase-admin to retrieve data and using Netlify Lambda functions to call the service. This is basically it.

Here is my code:

exports.handler = (event, context, callback) => {
  const { id = "toronto" } = event.queryStringParameters;
  const cityRefs = dbInstance.collection("cities");
  console.log("req.params.id", id);

  if (id === "mumbai") {
    console.log("in here", id);
    let cityRef = cityRefs.doc("id1");
    return cityRef
      .get()
      .then(doc => {
        if (!doc.exists) {
          console.log("No such document!");
        } else {
          console.log("Document data:", doc.data());
          callback(null, {
            statusCode: 200,
            body: doc.data()
          });
        }
      })
      .catch(err => {
        console.log("Error getting document", err);
        callback(err);
      });
    }

}

I keep getting the below error. I'm not exactly sure I'm doing wrong.

Function invocation failed: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type number

3
  • What line in the code you shared raises that error? Commented Jun 30, 2019 at 20:49
  • I do see the console log in here but then right after that the error occurs Commented Jul 1, 2019 at 14:47
  • 1
    You might try wrapping doc.data() in JSON.stringify(). You may also get more responses (and lots of friendly folks) on the Netlify Community! community.netlify.com/c/netlify-platform/functions Commented Jul 1, 2019 at 18:45

1 Answer 1

5

I figured it out. The reason why it didn't work is because of firebase-admin was being bundled. So I used https://www.npmjs.com/package/webpack-node-externals to bundle firebase-admin. I added this to webpack.functions.js:

const nodeExternals = require("webpack-node-externals");

module.exports = {
  externals: [nodeExternals()]
};

and I run the netlify lambda function with the following command:

"start:lambda": "netlify-lambda serve src/functions --config ./webpack.functions.js"
Sign up to request clarification or add additional context in comments.

1 Comment

when using external got this error "SyntaxError: Cannot use import statement outside a module"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.