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
{{ message }}
Repository navigation
use --env-file on localhost supabase start / stop / reset #1518
Describe the bug
I'm not sure if this is a bug or a needed feature, but I would like to be able to load a different .env file name besides just .env. Apparently this is possible for local edge functions per Managing Secrets and Environment Variables, but not possible for the whole supabase? This doesn't make sense to me why it would only be available for local function testing and not the whole config.toml, so perhaps I am missing something?
To Reproduce
Steps to reproduce the behavior:
Run localhost with supabase start --env-file ./.env.development
Expected behavior
It would load the .env.development (or whatever name), instead of throwing an error:
unknown flag: --env-file
Desktop (please complete the following information):
OS: Windows 11
Version of CLI 1.99.5
Version of Node.js 18
Thanks,
J
Reacted by misha sawangwan, Shubs, Matsu, Felix K, grumpy-miner, Han Qiao, iharuya and Brad Barbin
That I know of, supabase start does not use a --env.file flag, but you can source the env file you want to use locally in your terminal and supabase start will see those variables when you run start.
source is specific to unix and still a work around. I am using Windows (statistically most programmers do), and I don't want to declare all my projects env variables globally.
This needs to be implemented as a --env-file flag so that it can work for Windows users as well.
I've also come to want this. Mainly because I want to be creating a dev setup, where I could have a simple setup steps for our dev team on varying machines (unix, windows, etc.) without having to have separate instructions on each machine.
Running supabase from npx or a local installation is already quite cross-platform but if the project has any env variables, it becomes a burdain to make cross platform.
Actually implementing it to all of the cli api's though? That might require some monkey patching which I don't know is the best approach.
Could there be an approach where we create a loader for --env-file files and use it anywhere in the system? That would allow us to add this functionality to all of the cli endpoints, without having to trickle down the variable through all of the function calls.
Something along the lines of (writing js as go isn't my strong suit)
classLocalEnvManager{
#instance;staticgetInstance(){if(!this.#instance){this.#instance =newLocalEnvManager();}returnthis.#instance;}readSuppliedEnv(envFilePath){// envFilePath is supplied by user via `--env-file`constuserEnv=parseEnvFile(envFilePath,fsys)// This function is already in https://github.com/supabase/cli/blob/main/internal/functions/serve/serve.go#L180}}
And then we could just call the singleton instance throughout our cli pathways to trickle them around the different utils.DockerStart calls.
Would this singleton-ish approach make any sense? It would allow us to utilize the same flag across the cli API without having to completely butcher the function calls by adding more and more params to them and trickling the data down all of the pipes.
I'd be happy to take a stab at this if there's interest. Ping @sweatybridge or someone who's actively maintaining this project.
Personally, I would be happy if .env.local is automatically used in the local development environment. .env.local is often included in .gitignore and can safely handle environmental counts.
Reacted by Tristan Lerisse, Naman Kumar, Anderson Mamede, Safi Nettah, Matsu, Shubs, Han Qiao, Pete and Nicholas Molen
Personally, I would be happy if .env.local is automatically used in the local development environment.
I like this suggestion as well. We can probably follow the convention documented by godotenv. While it's not as explicit as --env-file flag, it does save quite a lot of keystrokes when starting and stopping.
If anyone would like to contribute a PR, this would be the code to update:
After upgrading to the latest version of Supabase, I am still unable to use environment variables in my local env, getting:
Error evaluating "env(<VARIABLE>)": environment variable <VARIABLE> is unset.
I tried to source .env before running supabase start. And I had the same results renaming the env file .env.development.local, .env.local, and .env.development.
I also reset all docker containers and volumes with docker rm $(docker ps -a -q) and docker volume rm $(docker volume ls -q --filter dangling=true)
Desktop environment
OS: Ubuntu 22.04.4 LTS x86
CLI: v1.191.3 and v1.117.0
Node: v20.12.0
Update
Solved. In the .env file, prepending export before each variable and calling source .env && supabase <command> works.
However, this is undocumented.
Reacted by Raul Fernandez van Dijk and Elior Buskila
none of these .env files seem to work for me, including prefixing export. E.g. when I set AUTH_JWT_SECRET in an .env then restart supbase it still uses the default key:
For functions I need to use npx supabase functions serve --env-file .env but for other commands there's no such option and there's no mention in the docs on how to actually set the JWT secret either
You want to use SUPABASE_AUTH_JWT_SECRET in .env file. I will create a separate issue to improve the docs on config.toml since that trips up users quite often.
Hi @sweatybridge thank you for all of your work! Where can I find documentation on what the .env file key names should be? Specifically for the anon and service key definitions
Is this supposed to substitute values in config.toml as well when starting? i.e. project-id = "env(PROJECT_ID)" is not getting substituted by values present in .env file. It didn't work by adding values through dotenv-cli either.
My project structure is:
package.json
.env
supabase
|-- config.toml
|-- other files
@sweatybridge this didn't work for me for functions with the supabase start with any combination of SUPABASE_ENV=local supabase start or sourcing before as suggested above source supabase/functions/.env.local && supabase start... etc. Tried the files at different levels (repo root, supabase/, supabase/functions).
only the variables under .env on supabase/functions are pulled into the Edge functions runtime.
For me, I use .env for local testing, and if I need to test prod locally, it won't be a local supabase (you can only run one at a time anyway), it will connect directly to my hosted prod database. If I had a staging, it would probably be a hosted free tier for testing only.
Activity
bombillazo commentedon Sep 22, 2023
That I know of,
supabase startdoes not use a--env.fileflag, but you can source the env file you want to use locally in your terminal and supabase start will see those variables when you run start.jdgamble555 commentedon Sep 22, 2023
sourceis specific to unix and still a work around. I am using Windows (statistically most programmers do), and I don't want to declare all my projects env variables globally.This needs to be implemented as a
--env-fileflag so that it can work for Windows users as well.J
jdgamble555 commentedon Sep 23, 2023
I should add that this works:
But we need this to work:
So not just
supabase start.J
[-]use --env-file on localhost supabase start[/-][+]use --env-file on localhost supabase start / stop / reset[/+]msawangwan commentedon Oct 10, 2023
this would be much appreciated.
Matsuuu commentedon Jan 11, 2024
I've also come to want this. Mainly because I want to be creating a dev setup, where I could have a simple setup steps for our dev team on varying machines (unix, windows, etc.) without having to have separate instructions on each machine.
Running supabase from npx or a local installation is already quite cross-platform but if the project has any env variables, it becomes a burdain to make cross platform.
After reading through Function.run codes and Start.run codebases, I don't think it's impossible to just Boop some env variables on board.
Actually implementing it to all of the cli api's though? That might require some monkey patching which I don't know is the best approach.
Could there be an approach where we create a loader for
--env-filefiles and use it anywhere in the system? That would allow us to add this functionality to all of the cli endpoints, without having to trickle down the variable through all of the function calls.Something along the lines of (writing js as go isn't my strong suit)
And then we could just call the singleton instance throughout our cli pathways to trickle them around the different
utils.DockerStartcalls.Would this singleton-ish approach make any sense? It would allow us to utilize the same flag across the cli API without having to completely butcher the function calls by adding more and more params to them and trickling the data down all of the pipes.
I'd be happy to take a stab at this if there's interest. Ping @sweatybridge or someone who's actively maintaining this project.
kobago commentedon Jan 12, 2024
Personally, I would be happy if
.env.localis automatically used in the local development environment..env.localis often included in.gitignoreand can safely handle environmental counts.sweatybridge commentedon Apr 20, 2024
I like this suggestion as well. We can probably follow the convention documented by godotenv. While it's not as explicit as
--env-fileflag, it does save quite a lot of keystrokes when starting and stopping.If anyone would like to contribute a PR, this would be the code to update:
cli/internal/utils/config.go
Line 485 in 4f83327
sweatybridge commentedon Apr 30, 2024
CLI now supports the following precedence order when loading
.envfiles.gitignoreit?.env.development.local.env.test.local.env.production.local.env.local.env.local.env.development.env.test.env.production.env.env.envRef: https://github.com/bkeepers/dotenv?tab=readme-ov-file#customizing-rails
gorango commentedon Sep 2, 2024
After upgrading to the latest version of Supabase, I am still unable to use environment variables in my local env, getting:
I tried to
source .envbefore runningsupabase start. And I had the same results renaming the env file.env.development.local,.env.local, and.env.development.I also reset all docker containers and volumes with
docker rm $(docker ps -a -q)anddocker volume rm $(docker volume ls -q --filter dangling=true)Desktop environment
Update
Solved. In the
.envfile, prependingexportbefore each variable and callingsource .env && supabase <command>works.However, this is undocumented.
tommedema commentedon Sep 7, 2024
none of these .env files seem to work for me, including prefixing export. E.g. when I set AUTH_JWT_SECRET in an .env then restart supbase it still uses the default key:
JWT secret: super-secret-jwt-token-with-at-least-32-characters-long
For functions I need to use npx supabase functions serve --env-file .env but for other commands there's no such option and there's no mention in the docs on how to actually set the JWT secret either
sweatybridge commentedon Sep 8, 2024
You want to use
SUPABASE_AUTH_JWT_SECRETin .env file. I will create a separate issue to improve the docs on config.toml since that trips up users quite often.komposer-aml commentedon Sep 29, 2024
Hi @sweatybridge thank you for all of your work! Where can I find documentation on what the .env file key names should be? Specifically for the anon and service key definitions
komposer-aml commentedon Sep 29, 2024
Never mind I found something!! If anyone else finds this via a Google search, I was able to find it at this repo's README:
https://github.com/supabase/fly-preview
manizm commentedon Oct 15, 2024
Is this supposed to substitute values in config.toml as well when starting? i.e.
project-id = "env(PROJECT_ID)"is not getting substituted by values present in .env file. It didn't work by adding values through dotenv-cli either.My project structure is:
joelpramos commentedon Dec 25, 2025
@sweatybridge this didn't work for me for functions with the
supabase startwith any combination ofSUPABASE_ENV=local supabase startor sourcing before as suggested abovesource supabase/functions/.env.local && supabase start... etc. Tried the files at different levels (repo root, supabase/, supabase/functions).only the variables under
.envonsupabase/functionsare pulled into the Edge functions runtime.any thoughts here?
jdgamble555 commentedon Dec 25, 2025
For me, I use
.envfor local testing, and if I need to test prod locally, it won't be a local supabase (you can only run one at a time anyway), it will connect directly to my hosted prod database. If I had a staging, it would probably be a hosted free tier for testing only.So not really needed when you think about it.
J