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

listParam isn't loaded successfully in the emulator #1605

Open
tzappia opened this issue Sep 8, 2024 · 4 comments
Open

listParam isn't loaded successfully in the emulator #1605

tzappia opened this issue Sep 8, 2024 · 4 comments

Comments

@tzappia
Copy link

tzappia commented Sep 8, 2024

Related issues

#1523

[REQUIRED] Version info

node:

v22.8.0

firebase-functions:

5.1.1

firebase-tools:

13.16.0

firebase-admin:

12.4.0

[REQUIRED] Test case

import { beforeUserCreated } from "firebase-functions/v2/identity";
import { myList } from './params.js';

export const beforecreated = beforeUserCreated((event) => {
  console.log('My list', myList.value());
});

In params.js

export const myList = defineList('MY_LIST', { default: [] });

In env.local

MY_LIST=something,somethingElse

[REQUIRED] Steps to reproduce

Run a function that uses a listParam, in this case I try to create a user so the beforeUserCreated blocking function is invoked.

[REQUIRED] Expected behavior

console log shows "My list [something, somethingElse]"

[REQUIRED] Actual behavior

>  {"severity":"ERROR","message":"Unhandled error SyntaxError: Unexpected token 's', \"something,somethingElse\" is not valid JSON\n    at JSON.parse (<anonymous>)\n    at ListParam.runtimeValue (/Users/tzappia/workspace/hrvst/functions/node_modules/firebase-functions/lib/params/types.js:378:26)\n    at ListParam.value (/Users/tzappia/workspace/hrvst/functions/node_modules/firebase-functions/lib/params/types.js:39:21)\n    at file:///Users/tzappia/workspace/hrvst/functions/lib/triggers/users.js:50:49\n    at wrappedHandler (/Users/tzappia/workspace/hrvst/functions/node_modules/firebase-functions/lib/v2/providers/identity.js:58:39)\n    at /Users/tzappia/workspace/hrvst/functions/node_modules/firebase-functions/lib/common/providers/identity.js:458:28\n    at /Users/tzappia/workspace/hrvst/functions/node_modules/firebase-functions/lib/common/onInit.js:33:16\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n    at async runFunction (/Users/tzappia/.nvm/versions/node/v22.8.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:506:9)\n    at async runHTTPS (/Users/tzappia/.nvm/versions/node/v22.8.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:531:5)"}

Were you able to successfully deploy your functions?

I was able to successfully deploy and the listParam seems to work fine in a production environment. Is the emulator parsing the .env file differently in the emulator vs. production? Seems to be a similar behaviour in the linked bug report that was closed.

@google-oss-bot
Copy link
Collaborator

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@exaby73
Copy link
Contributor

exaby73 commented Sep 12, 2024

Hello @tzappia. Could you try wrapping the value in [] and trying again?. So MY_LIST=something,somethingElse will become MY_LIST=[something,somethingElse]

@exaby73 exaby73 added Needs: Author Feedback Issues awaiting author feedback and removed needs-triage labels Sep 12, 2024
@tzappia
Copy link
Author

tzappia commented Sep 12, 2024

@exaby73 that works in the emulator, but I'm not willing to try it in production (don't want to break my live deployment!) As noted in the related issues, I expect it to fail in production.

@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Sep 12, 2024
@BenJackGill
Copy link

BenJackGill commented Oct 8, 2024

I did some testing.

For the emulator to work with defineList the .env file must have:

  1. Entire list wrapped in brackets.
  2. Each word wrapped in double quotes. Single quotes do not work.
  3. Separated by a comma. Using a space between each list item has does not effect the outcome. ["oranges and pears", "apples"] (with a space between list items) and ["oranges and pears","apples"] (without a space between list items) both work the same.

Like this:

EXAMPLE_LIST=["oranges and pears", "apples"]

But this style does not work in production.

It creates one list item of ["oranges and pears", and another list item of "apples"] which is obviously wrong. It seems to be splitting at the , and including the brackets and quotes and the spaces between each list item.

To make it work in production we need this in the .env file:

EXAMPLE_LIST=oranges and pears,apples

But as the original issue has raised, this format does not work with the emulator.

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

No branches or pull requests

4 participants