george43g / better-firebase-functions

This repo provides functionality for a better way of organising files, imports and function triggers in Firebase Cloud Functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

exportFunctions has an issue creating unique functions

bhr opened this issue · comments

I've been trying to use better-firebase-functions following the instructions from medium as well as here.

The issue I'm experiencing is that the ts modules are not exported as unique functions but rather as their folder.

Not sure what I'm doing wrong. Are there any logs I can inspect to see what's going on?
Thanks for giving any pointers!

The file structure:
Screen Shot 2020-07-04 at 10 43 10 AM

index.ts

import { exportFunctions } from 'better-firebase-functions'
exportFunctions({ __filename, exports });

Output when running firebase deploy --only functions


i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@ lint /Users/benedikt/vestico/firebase/functions
> eslint .

Running command: npm --prefix "$RESOURCE_DIR" run build

> functions@ build /Users/benedikt/vestico/firebase/functions
> tslint --project tsconfig.json && ./node_modules/.bin/tsc

✔  functions: Finished running predeploy script.
i  functions: ensuring necessary APIs are enabled...
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (84.72 KB) for uploading
✔  functions: functions folder uploaded successfully
i  functions: creating Node.js 10 (Beta) function api-auth(europe-west1)...
i  functions: creating Node.js 10 (Beta) function api-db(europe-west1)...
i  functions: creating Node.js 10 (Beta) function api-db(europe-west1)...
i  functions: creating Node.js 10 (Beta) function api-db(europe-west1)...
i  functions: creating Node.js 10 (Beta) function api-http(europe-west1)...
i  functions: creating Node.js 10 (Beta) function api-http(europe-west1)...

The following functions are found in your project but do not exist in your local source code:
        api-auth(europe-west1)
        api-db(europe-west1)
        api-http(europe-west1)

If you are renaming a function or changing its region, it is recommended that you create the new function first before deleting the old one to prevent event loss. For more info, visit https://firebase.google.com/docs/functions/manage-functions#modify

? Would you like to proceed with deletion? Selecting no will continue the rest of the deployments. Yes
i  functions: deleting function api-auth(europe-west1)...
i  functions: deleting function api-db(europe-west1)...
i  functions: deleting function api-http(europe-west1)...
⚠  functions: failed to create function api-http
HTTP Error: 409, Function api-http in region europe-west1 in project vestico-dev already exists
⚠  functions: failed to create function api-db
HTTP Error: 409, Function api-db in region europe-west1 in project vestico-dev already exists
⚠  functions: failed to create function api-db
HTTP Error: 409, Function api-db in region europe-west1 in project vestico-dev already exists
⚠  functions: failed to create function api-db
HTTP Error: 409, Function api-db in region europe-west1 in project vestico-dev already exists
⚠  functions: failed to create function api-auth
HTTP Error: 409, Function api-auth in region europe-west1 in project vestico-dev already exists
⚠  functions: failed to create function api-http
HTTP Error: 409, Function api-http in region europe-west1 in project vestico-dev already exists
✔  functions[api-db(europe-west1)]: Successful delete operation. 
✔  functions[api-http(europe-west1)]: Successful delete operation. 
✔  functions[api-auth(europe-west1)]: Successful delete operation. 


Functions deploy had errors with the following functions:
        api-auth
        api-db
        api-db
        api-db
        api-http
        api-http


To try redeploying those functions, run:
    firebase deploy --only functions:api-auth,functions:api-db,functions:api-db,functions:api-db,functions:api-http,functions:api-http


To continue deploying other features (such as database), run:
    firebase deploy --except functions

Error: Functions did not deploy properly.

Output when running firebase serve:

=== Serving from '/Users/benedikt/vestico/firebase'...

⚠  Your requested "node" version "10" doesn't match your global version "12"
✔  functions: functions emulator started at http://localhost:5001
i  functions: Watching "/Users/benedikt/vestico/firebase/functions" for Cloud Functions...
i  hosting: Serving hosting files from: public
✔  hosting: Local server: http://localhost:5000
✔  functions[api-http/bodyDoubles/computeFromPosts]: http function initialized (http://localhost:5001/vestico-dev/europe-west1/api-http/bodyDoubles/computeFromPosts).
✔  functions[api-http/startRedeem]: http function initialized (http://localhost:5001/vestico-dev/europe-west1/api-http/startRedeem).
i  functions[api-auth/onCreate]: function ignored because the auth emulator does not exist or is not running.
i  functions[api-db/pointsActions/onCreate]: function ignored because the firestore emulator does not exist or is not running.
i  functions[api-db/pointsActions/onUpdate]: function ignored because the firestore emulator does not exist or is not running.
i  functions[api-db/redeemRequests/onCreate]: function ignored because the firestore emulator does not exist or is not running.

I was reading @george43g 's other article on the subject too and tried to append the proposed func suffix to the TS files, e.g. on-create.func.ts. It didn't help though. The function names are still not recognized properly

After applying the fix from #11 and inserting admin.initializeApp(functions.config().firebase); at the top of index.ts it seems to be working!
I'm not sure why initializeApp was needed since I used the conveniences discussed in #10 .

I will bundle code to initialise apps automatically once I update the build config in the repo and also work out why the automatic releases arent working.