ncc
ncc copied to clipboard
Incorrect Compilation of Firebase Parameterized Variables by ncc
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
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!