Skip to content

fix(functions): edge-runtime template offline bootstrap (#45570)#5171

Open
ChrisJr404 wants to merge 1 commit intosupabase:developfrom
ChrisJr404:fix/edge-runtime-offline-bootstrap-45570
Open

fix(functions): edge-runtime template offline bootstrap (#45570)#5171
ChrisJr404 wants to merge 1 commit intosupabase:developfrom
ChrisJr404:fix/edge-runtime-offline-bootstrap-45570

Conversation

@ChrisJr404
Copy link
Copy Markdown

What

The edge-runtime entrypoint that supabase start writes into /root/index.ts (embedded from internal/functions/serve/templates/main.ts) starts with two remote imports:

import { STATUS_CODE, STATUS_TEXT } from "https://deno.land/std/http/status.ts";
import * as posix from "https://deno.land/std/path/posix/mod.ts";

Deno's graph builder resolves these every time the worker boots, so the runtime container fails to come up when the host has no network access.

Reported in supabase/supabase#45570:

error: TypeError: error sending request from 127.0.0.1:50932 for https://deno.land/std/http/status.ts (resolved to 2606:50c0:8000::153:443): client error (Connect): tcp connect error: Network is unreachable (os error 101): Network is unreachable (os error 101)
    at file:///root/index.ts:1:42

Why this happens

The image is supabase/edge-runtime:vX.Y.Z (pulled, not built here), and index.ts is materialised on each container start via the embedded template — there is no build-time deno cache step we can hook into to pre-warm the module graph for these URLs. Pinning to JSR hits the same wall: jsr: specifiers also require a registry round-trip on first use unless previously cached.

Fix

Inline the very small std surface this template actually depends on and drop the remote imports. Concretely:

Was Now
STATUS_CODE.{OK,Unauthorized,NotFound,InternalServerError,ServiceUnavailable} from https://deno.land/std/http/status.ts local STATUS_CODE const with the same five numeric values
STATUS_TEXT[STATUS_CODE.InternalServerError] from the same module local STATUS_TEXT record with the same five reason phrases
posix.{dirname,join,toFileUrl} from https://deno.land/std/path/posix/mod.ts local posix object with the same three helpers

The posix shim's outputs were cross-checked against node:path.posix for the path shapes this template constructs (/supabase/functions/<name>/index.ts, package-json discovery joins, absolute-to-file:// conversion). STATUS_TEXT reason phrases match RFC 9110.

This is the smallest viable diff that makes offline boot work — no Dockerfile changes, no new //go:embed plumbing, no surrounding refactor.

The jsr:@panva/jose@6 import on line 1 is unaffected: edge-runtime images already ship that module pre-cached (it has been in this template since #4721), which is why JWT verification works offline today and the std imports are the only blocker.

Regression test

Added TestMainTemplateNoRemoteImports in internal/functions/serve/serve_test.go. It scans the embedded template for https://deno.land/, http://deno.land/, https://esm.sh/, https://cdn.jsdelivr.net/, and https://unpkg.com/ and fails if any reappear. If anyone re-introduces a bare URL import here, the test catches it before the next offline-start regression.

Verification

  • go build ./... clean
  • go test ./internal/functions/... all pass (incl. existing TestServeCommand, TestServeFunctions, and the new pin)
  • go vet ./... clean

Closes supabase/supabase#45570

The embedded edge-runtime entrypoint imported two std modules from
deno.land at the top of the file. Deno's graph builder fetches those
URLs every time the worker boots, so `supabase start` cannot bootstrap
the runtime container without internet access.

Inline the small surface that the template actually uses (5 status
codes + 1 status-text lookup, plus posix.dirname/join/toFileUrl) and
drop the remote imports. The local posix shim was checked against
node:path.posix for the path shapes this file constructs.

Add a regression-pin test that fails if any HTTPS deno.land/esm.sh/
cdn.jsdelivr/unpkg import is reintroduced into templates/main.ts.

Closes supabase/supabase#45570
@ChrisJr404 ChrisJr404 requested a review from a team as a code owner May 5, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Supabase fails to run offline without an internet connection

1 participant