How to use Doppler with Firebase functions?

I was able to use doppler locally while using Firebase Emulator using the docs in Doppler but am not sure how to use it in production. The docs didn’t help me much regarding production. It refers us to firebase docs, so is it trying to indicate that we need to use “firebase functions:config:set” to set each env variable we want to use?

Hi @ytrkptl and welcome to the Doppler community!

It seems our Firebase docs are in need of an update but for now, I’ve got the next best thing which is a sample repository that shows how to:

I’ll get to updating the docs next week but hopefully the sample repository will give you the coding patterns you need for now and I’d love to get your feedback!

Hi there, thank you for replying. Here is what I did so far:

  1. Updated package.json inside my functions folder to match the scripts in the 2nd and 3rd link you provided.
  2. Updated environment.js inside the functions folder to match the first link you provided above.
  3. From within the function directory, I ran npm run config-env-set

Here is the result I got. It threw an error showing the following:

I then tried to deploy my function, which threw an error stating the following:

Also, while trying using the existing docs yesterday, one error I received mentioned something about firebase not allowing uppercase letters when manually trying to set an env variable.

Any help would be appreciated with this error.

No worries! We’ll figure it out!

Are you able to run the ‘doppler secrets download’ command in your package.json to confirm its actually returning JSON?

Can you also paste in the text commands for the config set and deploy commands from your package.json?

I think it’s really close.

Running doppler secrets download from within the functions folder created a doppler.json file in that folder with some gibberish in it. My package.json looks the same as the one you linked except that I did not enable linting.

Here is what I had prior to our discussion:

I also tried to update the package.json based on the links you provided. Here is what it looks like now:

Running npm run config-env-set shows the following this time around:


Thank you for the quick replies.

I believe this may be a quoting issue related to the shell that the script is executing in.

It appears you’re on Windows? What shell are you currently using?

Can you try running each command below to verify that what I’m seeing is consistent with your results in your shell:

# 1. This should work
firebase functions:config:set env="$(echo '{"TEST":"testing"}')"

# 2. This should also work
firebase functions:config:set env='{"TEST":"testing"}'

# 3. This should fail
firebase functions:config:set env="{"TEST":"testing"}"

Then can you try executing the code for the config-env-set script, but replace \" with " and run it directly in your shell (not through npm).

firebase functions:config:unset env && firebase functions:config:set env="$(doppler secrets download --config dev --no-file --format json --silent)"

Did that work?

If it does, that’s great news, as it’s now just a case of configuring npm to use the shell environment in which you executed the command.

If not, then we’ll likely need to look at a different shell for executing the command or perhaps writing a Node script that uses the Firebase SDK.

The first command failed stating “Error: Invalid argument, each config value must have a 2-part key (e.g.”

I just use the Command Prompt on my Windows 10.

Running the first command using the Git Bash terminal worked.

I ran that command you asked but replaced dev with prd like so

firebase functions:config:unset env && firebase functions:config:set env="$(doppler secrets download --config prd --no-file --format json --silent)"

and that created a config in firebase but with only the “env” variable set to an object like so:

Awesome! That’s exactly the result you want!

So it sounds like configuring npm to use the Git bash terminal instead of the default Command Prompt is the right solution.

You should be able to verify the shell npm is using by running:

npm config ls -l

Then find the value for script-shell.

To change to using Git bash, override the default script-shell and set to the path of the Git Bash executable:

npm config set script-shell "C:\Program Files\Git\bin\bash.exe"

All this does is create a file at ~/.npmrc that contains this override so nothing magical going on.

You should then be able to run the npm run config-env-set command without any issues.

Hope that clears this up for you and let me know how you go!

1 Like