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

Firebase-functions v4 breaks better-firebase-functions: No functions are detected during deployment

bhr opened this issue · comments

After updating to firebase-functions 4.0.1 and trying to deploy the functions, firebase doesn't find any cloud functions anymore. It shows the following error:

The following functions are found in your project but do not exist in your local source code:
        auth-onCreate(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. No

index.ts

import { exportFunctions } from 'better-firebase-functions';
import camelCase from 'camelcase';

exportFunctions({
  __filename,
  exports,
  functionDirectoryPath: './api',
  funcNameFromRelPath: myFuncNameAlgo,
});

function myFuncNameAlgo(relPath: string): string {
  const sep = '/';
  const relPathArray = relPath.split(sep); /* ? */
  const fileName = relPathArray.pop(); /* ? */
  const relDirPathFunctionNameChunk = relPathArray.map((pathFragment) => camelCase(pathFragment)).join(sep);
  const fileNameFunctionNameChunk = camelCase(fileName!.split('.')[0]);
  const funcName = relDirPathFunctionNameChunk ? `${relDirPathFunctionNameChunk}${sep}${fileNameFunctionNameChunk}` : fileNameFunctionNameChunk;
  return funcName.split(sep).join('-');
}

With firebase-functions 3.24.1 deployment works and the functions are picked up correctly.

The transpiled JS files look as expected and correctly use exports.default

Sample function (TS->JS)

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const functions = __importStar(require("firebase-functions"));
exports.default = functions
    .region('europe-west1')
    .auth.user()
    .onCreate((user) => {
    …
    return Promise.resolve();
});

Is there any way to debug what's going wrong?

commented

I've not yet had a chance to investigate this - had to take the last few months off work. I need to investigate how useful this repo is given that Firebase Functions now supports ESM modules (import) statements directly and what impact this has on performance. There may still be a benefit to using webpack to minify all the function code as that did increase performance when I initially wrote and tested this library.

I have the same problem as bhr and would very much appreciate a disclaimer in the README.

commented

I've tested with v4 and it works for me - however my whole dir is compiled with webpack before deployment (shouldn't change things) - I'll investigate further what's causing the issue.

For me after upgrading from 4.0.0 to 6.0.0 none of my functions are being detected anymore. In this case it deleted all my staging environment functions.

Btw, I downgraded back to 4.0.0 and it's working again.

Also v2 functions seem to not get picked up properly with this lib, I was hoping to upgrade to 6.0.0 in case it was fixed there.

Same problem for me -- no functions are being detected. I tried figuring out what the problem was, but am struggling to figure it out

Experiencing the same issue. Downgrading to 4.0.0 resolves it for both v1 and v2 functions.

Experiencing the same issue. Downgrading to 4.0.0 resolves it for both v1 and v2 functions.

Likewise here.

Just don't use this library, it has been abandoned. No point in having your plan rely on it.

I got the issue as well, I cloned the project locally to debug and found out the glob matching couldn't find the files.

I made the following change and it fixed.

exportFunctions({
	__filename,
	exports,
	enableLogger: true,
+	searchGlob: '**/*.js',
});

Now I see: 👍

functions: Loaded functions definitions from source: ...
functions[us-central1-...]: firestore function initialized.

Something else might be going on since this doesn't seem like something that would change between firebase versions?