Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bhr opened this issue Oct 20, 2022 · 15 comments

Comments

@bhr
Copy link

bhr commented Oct 20, 2022

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?

@george43g
Copy link
Owner

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.

@paul019
Copy link

paul019 commented Aug 7, 2023

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

@george43g
Copy link
Owner

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.

@cgossain
Copy link

cgossain commented Oct 1, 2023

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.

@cgossain
Copy link

cgossain commented Oct 4, 2023

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.

@george43g
Copy link
Owner

george43g commented Oct 4, 2023 via email

@andr3wV
Copy link

andr3wV commented Jan 31, 2024

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

@oconnorjoseph
Copy link

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

@roomman
Copy link

roomman commented Apr 11, 2024

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

Likewise here.

@george43g
Copy link
Owner

george43g commented Apr 11, 2024 via email

@andr3wV
Copy link

andr3wV commented Apr 11, 2024

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

@george43g
Copy link
Owner

george43g commented Apr 11, 2024 via email

@KyleSmith0905
Copy link

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?

@george43g
Copy link
Owner

george43g commented Apr 18, 2024 via email

@george43g
Copy link
Owner

george43g commented Apr 18, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants