You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 variablesconstREGION=defineString("REGION");constTIMEOUT_SECONDS=defineInt("TIMEOUT_SECONDS");constSAY_HELLO=defineString("SAY_HELLO");// Firebase functionexportconsthelloWorld=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 functionexportconsthelloWorld=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.
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!
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:
However, after
ncc
compilation and Firebase deployment, I encounter errors for the parameterized variables used in the function config, such as this:This only effects the function config variables. If I hardcode the function config
REGION
andTIMEOUT_SECONDS
variables and leave theSAY_HELLO
variable in the function body then it works:Note: This issue is unique to the
ncc
compilation step, as Firebase parameterized variables function as expected when skipping thencc
compilation step.I am using
ncc
version0.38.1
Here is an example repo showing the error: https://github.com/BenJackGill/ncc-error
The text was updated successfully, but these errors were encountered: