Skip to content

Failed to deploy with serviceAccount as StringParam defined in .env file #6365

@ZakarY2HM6f

Description

@ZakarY2HM6f

Environment info

firebase-tools:
12.5.4

Platform:
macOS

Test case

.env

SERVICE_ACCOUNT=(service account here)

index.js

const {defineString} = require("firebase-functions/params");
const {setGlobalOptions} = require("firebase-functions/v2/options");
const {onRequest} = require("firebase-functions/v2/https");

const serviceAccount = defineString("SERVICE_ACCOUNT");

setGlobalOptions({
  serviceAccount: serviceAccount,
});

exports.sayHello = onRequest(
  (req, res) => {
    res.status(200).send("Hello world!");
  }
);

↑ this does not work, but this works ↓

workaround.js

...

setGlobalOptions({
  serviceAccount: serviceAccount.value(),
});

exports.sayHello = onRequest(
  (req, res) => {
    res.status(200).send("Hello world!");
  }
);

Steps to reproduce

firebase deploy

Expected behavior

to just deploy normally

Actual behavior

for index.js, the output:

...
⚠  functions: HTTP Error: 400, {{ params.SERVICE_ACCOUNT }} should be a valid email or unique id.
⚠  functions:  failed to update function projects/***/locations/***/functions/sayHello
Failed to update function projects/***/locations/***/functions/sayHello
...

for workaround.js, the output:

...
i  functions: Loading and analyzing source code for codebase default to determine what to deploy
Serving at port 8079

{"severity":"WARNING","message":"params.SERVICE_ACCOUNT.value() invoked during function deployment, instead of during runtime."}

{"severity":"WARNING","message":"This is usually a mistake. In configs, use Params directly without calling .value()."}
{"severity":"WARNING","message":"example: { memory: memoryParam } not { memory: memoryParam.value() }"}
...

workaround deploys sucessfully, but its suggestions (without .value()) fails, as shown in index.js

On error, hard-coded values are printed out as is, while StringParam is shown as {{ params.SERVICE_ACCOUNT }}, suggesting the CLI may not have evaluated the Param as a string before validating and using the value.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions