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

Incorrect Compilation of Firebase Parameterized Variables by ncc #1129

Open
BenJackGill opened this issue Oct 21, 2023 · 1 comment
Open
Labels
bug Something isn't working

Comments

@BenJackGill
Copy link

BenJackGill commented Oct 21, 2023

I am using ncc to compile my monorepo before deploying to Firebase Functions.

While ncc works well generally, it incorrectly compiles Firebase parameterized variables, leading to a deployment error.

According to Firebase documentation, parameterized variables should be used directly when accessed inside a function config, while .value() should be appended when accessed within the function body.

Here's an illustration of correct usage as per Firebase documentation:

import { defineString, defineInt } from "firebase-functions/params";
import { onRequest } from "firebase-functions/v2/https";

// Making the parameterized variables
const REGION = defineString("REGION");
const TIMEOUT_SECONDS = defineInt("TIMEOUT_SECONDS");
const SAY_HELLO = defineString("SAY_HELLO");

// Firebase function
export const helloWorld = onRequest(
  { region: REGION, timeoutSeconds: TIMEOUT_SECONDS }, // Usage in function config has no .value() appended
  (req, res) => {
    res.send(SAY_HELLO.value());, // Usage in the function body has .value() appended
  }
);

However, after ncc compilation and Firebase deployment, I encounter errors for the parameterized variables used in the function config, such as this:

Error: CEL expression 'params.TIMEOUT_SECONDS' is of an unsupported form

This only effects the function config variables. If I hardcode the function config REGION and TIMEOUT_SECONDS variables and leave the SAY_HELLO variable in the function body then it works:

// Firebase function
export const helloWorld = onRequest(
  { region: "australia-southeast1", timeoutSeconds: 100 }, // Hardcoding these to avoid the error
  (req, res) => {
    res.send(SAY_HELLO.value()); // Can leave this here because it does not cause an error
  }
);

Note: This issue is unique to the ncc compilation step, as Firebase parameterized variables function as expected when skipping the ncc compilation step.

I am using ncc version 0.38.1

Here is an example repo showing the error: https://github.com/BenJackGill/ncc-error

@styfle styfle added the bug Something isn't working label Oct 22, 2023
@BenJackGill
Copy link
Author

BenJackGill commented Oct 24, 2023

Further testing reveals that parameterized variables within the function's body will not work at all.

When a parameterized variable is present in the function's body, the deployment technically proceeds without errors, but it fails to prompt the user to input a value for SAY_HELLO. Consequently, the expected .env.<project_id> file, where the input should be stored, is not generated, rendering the value inaccessible within the function.

Even manually creating the required .env.<project_id> file with a key-value pair like SAY_HELLO=hello does not resolve the issue; the value remains unreachable within the function's body.

The combination of this issue with the errors described in my initial post renders parameterized variables unusable when processed by ncc. If anyone has a workaround to suggest before this bug is resolved in ncc, I would greatly appreciate it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants