cli
cli copied to clipboard
--env-file switch in functions serve fails, and .env ingestion in general is failing
Describe the bug
The command supabase functions serve --env-file ./.env yields:
Invalid env name: SUPABASE_PERSONAL_ACCESS_TOKEN. Env names cannot start with SUPABASE_.
This command was resorted to only because when using the bare supabase functions serve command, there were runtime errors as follows:
- Initially, the edge function attempted to use
process.envbut it wasn't accessible with npm: prefixed dotenv pkg (perhaps I did sthg wrong), therefore: - Switched to deno version of dotenv, with
import { config } from 'https://deno.land/x/[email protected]/mod.ts'and a call toconfig()prior toDeno.env.get()calls, which failed with:[Error] TypeError: Deno.readFileSync is not a function at parseFile (https://deno.land/x/[email protected]/mod.ts:100:55) at config (https://deno.land/x/[email protected]/mod.ts:41:16) at Object.handler (file:///home/deno/functions/faq-embeddings-agent/index.ts:62:3) at eventLoopTick (ext:core/01_core.js:182:7) at async handleHttp (ext:sb_core_main_js/js/http.js:96:17) - therefore, switched to
import { configAsync } from 'https://deno.land/x/[email protected]/mod.ts'and a call toawait configAsync(), which failed with:[Error] TypeError: Deno.readFile is not a function at parseFileAsync (https://deno.land/x/[email protected]/mod.ts:108:61) at configAsync (https://deno.land/x/[email protected]/mod.ts:48:22) at Object.handler (file:///home/deno/functions/faq-embeddings-agent/index.ts:62:9) at eventLoopTick (ext:core/01_core.js:182:7) at async handleHttp (ext:sb_core_main_js/js/http.js:96:17)
Hope that provides some context.
To Reproduce Run the command above.
Expected behavior .env file ingested without protest
Screenshots
If applicable, add screenshots to help explain your problem.
System information
Rerun the failing command with --create-ticket flag (preferred).
- Ticket ID: 58a7490ab6074b7497087a7417ecd5fa
Additional context If applicable, add any other context about the problem here.
- Browser [e.g. chrome, safari]
- n/a
- Version of supabase-js [e.g. v2.22.0]
- 2.39.3
- Version of Node.js [e.g. v16.20.0]
- 20.11.0
We don't allow env vars prefixed with SUPABASE_. Are you able to rename the env var to something else? For eg. APP_ACCESS_TOKEN.
If you want to avoid specifying --env-file flag, you can create supabase/functions/.env file. Those variables will be automatically injected into edge runtime container when serving locally. Remember that the same naming restrictions apply.
@sweatybridge I arrived at this error while looking at this page in the Supabase docs: https://supabase.com/docs/guides/functions/examples/send-emails
It specifically cites .env and it doesn't appear to be within the supabase/functions/ directory. Therefore, I added the RESEND_API_KEY to my local .env file in project root and got the error shown.
As-is, the error is also misleading or hard to understand.
Invalid env name: SUPABASE_URL. Env names cannot start with SUPABASE_. — Is it really an env name? That seems like the wrong term to use. Rather, Env vars cannot start with... makes more sense IMO.
Rather, Env vars cannot start with... makes more sense IMO.
Yes, thanks for the suggestion. We are planning to change it so that env vars prefixed with supabase_ are automatically ignored with a warning. Hoping to land it this week
@sweatybridge
Rather, Env vars cannot start with... makes more sense IMO.
Yes, thanks for the suggestion. We are planning to change it so that env vars prefixed with supabase_ are automatically ignored with a warning. Hoping to land it this week
Any updates?
@colemilne54 this is released to beta channel.
npx supabase@beta functions serve
Bro so lame we can't start them with SUPABASE_ wut?! Delete that enforcement. I should be able to access my SUPABASE_JWT_SECRET from my .env.local from my NextJS project. This is wacko!
I think this is strange to enforce because all the reserved secrets in edge functions secret management dashboard start with "SUPABASE_". So essentially I need to duplicate secrets?
I might be missing something, but this makes it a little tricky to locally run edge functions that are pointed to cloud supabase instead of local supabase. It seems like I have to have a duplicate set of secrets which I point to when running locally.
I might be missing something, but this makes it a little tricky to locally run edge functions that are pointed to cloud supabase instead of local supabase. It seems like I have to have a duplicate set of secrets which I point to when running locally.
I have the same question. I am working on the edge functions and found out I cannot use SUPABASE_* as env var. could anyone explain more details about this enforcement?
I would have thought that the supabase CLI was simply ignoring env vars prefixed with SUPABASE_ because it was injecting it's own for the local supabase docker container. But that also doesn't appear to be the case. What's the point of ignoring these envs if not to provide the local values in their place? I too have resorted to duplicating env names (with different namings). Make it make sense please :)
This is definitely confusing on the part of Supabase. Since the built-in vars will be present in a deployment, you can just set a local only env var and have it be the fallback like so:
const supabaseUrl =
Deno.env.get("SUPABASE_URL") ?? Deno.env.get("LOCAL_DEV_SUPABASE_URL")!
const supabaseKey =
Deno.env.get("SUPABASE_SERVICE_ROLE_KEY") ??
Deno.env.get("LOCAL_DEV_SUPABASE_SERVICE_ROLE_KEY")!
This is definitely confusing on the part of Supabase. Since the built-in vars will be present in a deployment, you can just set a local only env var and have it be the fallback like so:
const supabaseUrl = Deno.env.get("SUPABASE_URL") ?? Deno.env.get("LOCAL_DEV_SUPABASE_URL")! const supabaseKey = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY") ?? Deno.env.get("LOCAL_DEV_SUPABASE_SERVICE_ROLE_KEY")!
It should be the other way around as SUPABASE_URL defaults to http://kong:8000.
const supabaseUrl =Deno.env.get("LOCAL_DEV_SUPABASE_URL") ??
Deno.env.get("SUPABASE_URL")!
const supabaseServiceRoleKey =
Deno.env.get("LOCAL_DEV_SUPABASE_SERVICE_ROLE_KEY")??
Deno.env.get("SUPABASE_SERVICE_ROLE_KEY") !