Why is my google cloud function not recognizing a dependency?

I am trying to implement a google cloud function to search text in my firestore database. The sample that I am following is here: https://firebase.google.com/docs/firestore/solutions/search?provider=algolia. When I try to deploy my function I get following error:

ReferenceError: algoliasearch is not defined

I tried running npm install algoliasearch which executed successfully however I get the same error.

Here are my dependencies in my package.json file which is located in my functions folder:

"dependencies": {
    "@google-cloud/vision": "^2.3.7",
    "algoliasearch": "^4.10.3",
    "bad-words": "^3.0.4",
    "child-process-promise": "^2.2.1",
    "firebase-admin": "^9.8.0",
    "firebase-functions": "^3.14.1",
    "mkdirp": "^1.0.4"
  },

Here is the code that is causing the error:

// Initialize Algolia, requires installing Algolia dependencies:
// https://www.algolia.com/doc/api-client/javascript/getting-started/#install
//
// App ID and API Key are stored in functions config variables
const ALGOLIA_ID = functions.config().algolia.app_id;
const ALGOLIA_ADMIN_KEY = functions.config().algolia.api_key;
const ALGOLIA_SEARCH_KEY = functions.config().algolia.search_key;

const ALGOLIA_INDEX_NAME = 'usernames';
const client = algoliasearch(ALGOLIA_ID, ALGOLIA_ADMIN_KEY);

algoiasearch is not a user-defined function.



Read more here: https://stackoverflow.com/questions/68473485/why-is-my-google-cloud-function-not-recognizing-a-dependency

Content Attribution

This content was originally published by David at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: