'Cloud functions builds and lints, but no URL is generated

I'm experimenting with ethers.js contract deployment inside a firebase cloud function. My functions build and compiles, but when I run either firebase serve --only functions or firebase deploy --only functions, it deploys one of the contracts exported in index.ts, ("helloWorld") but not the other one ("greet"), which is what I'm trying to test.

No errors are generated in the build step, and when I run firebase serve, I get a URL for helloWorld, but nothing (nor any error messages) on 'greet'.

Here's the contents of index.ts:

import {ethers, Wallet} from "ethers";
import * as functions from "firebase-functions";
import greetJson from "../contracts/greeter.json";

export const greet = functions.https.onRequest(async (request, response) => {
  const provider = new ethers.providers.JsonRpcProvider("http://localhost:8545");
  const signer = new
  Wallet("*redacted*",
      provider);
  console.log("starting deploy");
  const abi = greetJson.abi;
  const factory = new ethers.ContractFactory(abi, greetJson.bytecode, signer);
  const contract = await factory.deploy(["Ciao Bella"]);
  const greeter = await contract.deployed();
  const greetresult = await greeter.greet();
  response.send("Hello: " + greetresult);
});

export const helloWorld = functions.https.onRequest((request, response) => {
  functions.logger.info("Hello logs!", {structuredData: true});
  response.send("Hello from Firebase!");
});

here's the terminal output:

My-MacBook-Pro:functions jk$ npm run-script build

build tsc

My-MacBook-Pro:functions jk$ firebase serve --only functions
⚠  Your requested "node" version "16" doesn't match your global version "14". Using node@14 from host.
i  functions: Watching "/Users/jk/Documents/VSCodeProjects/BKC/bkc-cloud-blockchain/functions" for Cloud Functions...
✔  functions[us-central1-helloWorld]: http function initialized (http://localhost:5000/bkc-63bcf/us-central1/helloWorld).

That's it. Any idea why the greet function is ignored?



Solution 1:[1]

There's an option called Partial Deploys, to deploy specific Firebase functions.

For example:

$ firebase deploy --only functions:function1

And to deploy more than one function at once, you can use:

$ firebase deploy --only functions:function1,functions:function2

So for your case, you can run the command to deploy your two functions:

$ firebase deploy --only functions:greet,functions:helloWorld

Solution 2:[2]

This turned out to be a problem related to directory structure, and the include key in tsconfig.json.

If you put an include key like "include": ["src", "contracts"] in order to be able to import json files in the contracts folder, you end up writing to a lib folder that is an unexpected place, and is ignored. Best to make sure that if you need a folder to contain files that need to be included in your build, just put them under src and don't include an include key in your tsconfig when you run firebase serve

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 GGizmos