Skip to content

[bug] functions serve --env-file fails with 'An error occurred in Effect.tryPromise' (CLI 2.109.1) #5892

Description

@Jorge-Arroyo-Barahona

Summary

supabase functions serve <name> --env-file <file> fails with a generic An error occurred in Effect.tryPromise error in CLI 2.109.1. The --debug flag does not provide additional details. The Edge Function container (supabase_edge_runtime_<project>) is deleted (not just stopped) on failure, breaking the local stack until supabase stop && supabase start is run.

Severity: Medium — workaround available, only impacts local development (not CI/CD via supabase functions deploy, not production via Supabase Cloud).

Environment

  • OS: Windows 11 [Version 10.0.26200.8875] (also reproducible on WSL/Linux per error pattern)
  • Supabase CLI: 2.109.1 (latest stable at time of report)
  • Docker Desktop: 4.82.0
  • Postgres: 15 (via supabase start)
  • Edge runtime image: public.ecr.aws/supabase/edge-runtime:v1.74.2

Steps to reproduce

# 1. Initialize a Supabase project
supabase init

# 2. Create an Edge Function
mkdir -p supabase/functions/hello
cat > supabase/functions/hello/index.ts <<EOF
Deno.serve(() => new Response("hello"));
EOF

# 3. Start the local stack
supabase start

# 4. Create .env.local with at least one API key
cat > .env.local <<EOF
OPENAI_API_KEY=sk-proj-test
EOF

# 5. Reproduce the bug
supabase functions serve hello --no-verify-jwt --env-file .env.local

Expected behavior

The function is served, the env vars from .env.local are available in the container, requests to the function work.

Actual behavior

An error occurred in Effect.tryPromise
Try rerunning the command with --debug to troubleshoot the error.

Exit code: 1.

The container supabase_edge_runtime_<project> is deleted (not just stopped). To recover: supabase stop && supabase start.

With --debug

Loading profile from file: C:\Users\jorge\.supabase\profile
An error occurred in Effect.tryPromise

No additional info — the error originates from Effect.tryPromise (likely from effect-ts library used by the CLI), which swallows the original error.

Additional notes

  • The CLI also fails if you create a ~/.supabase/profile file with any content (e.g., default, {"id":"default"}, type: "test"). The format is undocumented and Unsupported Config Type "" errors result.
  • The CLI does not work if docker is not in PATH (e.g., when called from a non-interactive PowerShell session that doesn't initialize PATH the same way as a regular shell).

Working workaround

Replace supabase functions serve --env-file with a manual docker run:

docker run -d \
  --name supabase_edge_runtime_<project> \
  --network supabase_network_<project> \
  -v /path/to/functions:/path/to/functions:ro \
  -v supabase_edge_runtime_<project>:/root/.cache/deno \
  -v /path/to/wrapper.ts:/root/index.ts:ro \
  -p 8081:8081 \
  -w /path/to/project/backend \
  -e SUPABASE_URL=http://kong:8000 \
  -e SUPABASE_ANON_KEY=... \
  -e SUPABASE_SERVICE_ROLE_KEY=... \
  -e SUPABASE_INTERNAL_PUBLISHABLE_KEY=... \
  -e SUPABASE_INTERNAL_SECRET_KEY=... \
  -e SUPABASE_INTERNAL_JWT_SECRET=... \
  -e SUPABASE_JWKS='{"keys":[...]}' \
  -e SUPABASE_INTERNAL_HOST_PORT=54321 \
  -e SUPABASE_INTERNAL_FUNCTIONS_CONFIG='{"hello":{"verifyJWT":false,"entrypointPath":"supabase/functions/hello/index.ts"}}' \
  -e OPENAI_API_KEY=... \
  -e MINIMAX_API_KEY=... \
  --entrypoint sh \
  public.ecr.aws/supabase/edge-runtime:v1.74.2 \
  -c "edge-runtime start --main-service=/root --port=8081 --policy=per_worker"

wrapper.ts is a pre-generated file from a previous successful run of supabase functions serve (without --env-file), cached at C:\Users\<user>\AppData\Local\Temp\supabase-functions-serve-main-XXX\index.ts on Windows or /tmp/supabase-functions-serve-main-XXX/index.ts on Linux.

Probable cause

The CLI 2.109.1 uses an Effect library (likely effect-ts) to wrap the async docker run invocation. The wrapper fails silently. Suspected culprits:

  1. Conflict with --entrypoint when passed as a multi-arg string via -c
  2. Race condition with the docker rm of the previous container
  3. Bug in how the CLI serializes env vars that contain complex JSON (like SUPABASE_INTERNAL_FUNCTIONS_CONFIG)

Versions tested

Version Works? Notes
2.109.1 ❌ Fails Latest stable at time of report
2.107.x ⏳ Untested Hypothesis: bug was introduced in 2.108+

Validated workaround

Using the workaround above, an E2E test with MiniMax (OpenAI-compat provider) returned 200 OK with a valid deck:

{
  "response": {
    "kind": "deck",
    "title": "Scientific Study Techniques",
    "cards": [{"front": "...", "back": "..."}, ...]
  },
  "usage": {"tokensInput": 184, "tokensOutput": 274, "durationMs": 12194}
}

The workaround is documented in X:\joarr\agents\bin\restart-edge-with-keys.ps1 (PowerShell) for the JOARR FlashCards project.

Impact

  • Local devs: workaround required (manual docker run).
  • CI/CD: not impacted (uses supabase functions deploy).
  • Production: not impacted (uses Supabase Cloud).

Suggested fix

  1. Add better error logging to the Effect.tryPromise wrapper (log the original error before wrapping).
  2. Document the ~/.supabase/profile file format.
  3. If the bug is in env var serialization, use --env-file semantics that work with complex JSON.
  4. Test on Windows + WSL + macOS + Linux.

Reporter

JOARR Technologies (https://github.com/JOARR-Technologies/joarr-flashcards)
CLI user since 2026-07, building local-first apps with Edge Functions.

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions