anomalyco/sst · error

ErrCloudflareMissingAccount

ErrCloudflareMissingAccount

Error message

missing account

What it means

`ErrCloudflareMissingAccount` is returned by the Cloudflare provider's `Init` when no Cloudflare account ID can be resolved for the provider. The provider needs an account to scope resource containers (`identifier`) and exports `CLOUDFLARE_DEFAULT_ACCOUNT_ID`.

Source

Thrown at pkg/project/provider/cloudflare.go:28

	"net/http"
	"net/url"
	"os"
	"path/filepath"
	"strings"
	"sync"
	_ "unsafe"

	cloudflare "github.com/cloudflare/cloudflare-go"
	"github.com/sst/sst/v3/internal/util"
)

type CloudflareProvider struct {
	api              *cloudflare.API
	identifier       *cloudflare.ResourceContainer
	defaultAccountId string
}

var ErrCloudflareMissingAccount = fmt.Errorf("missing account")

func (c *CloudflareProvider) Env() (map[string]string, error) {
	return map[string]string{
		"CLOUDFLARE_DEFAULT_ACCOUNT_ID": c.defaultAccountId,
	}, nil
}

func (c *CloudflareProvider) Init(app, stage string, args map[string]interface{}) error {
	apiToken := os.Getenv("CLOUDFLARE_API_TOKEN")
	apiKey := os.Getenv("CLOUDFLARE_API_KEY")
	email := os.Getenv("CLOUDFLARE_EMAIL")
	if args["apiToken"] != nil {
		apiToken = args["apiToken"].(string)
	}
	if args["apiKey"] != nil {
		apiKey = args["apiKey"].(string)
	}
	if args["email"] != nil {

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Set `accountId` in the Cloudflare provider config in `sst.config.ts`
  2. Or export `CLOUDFLARE_ACCOUNT_ID` in your shell/CI environment
  3. Use an API token with the Account:Read permission so the account can be discovered

Example fix

// before
provider: {
  cloudflare: { apiToken: process.env.CLOUDFLARE_API_TOKEN }
}
// after
provider: {
  cloudflare: { apiToken: process.env.CLOUDFLARE_API_TOKEN, accountId: "your-account-id" }
}
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.CLOUDFLARE_ACCOUNT_ID && !sst.config()?.provider?.cloudflare?.accountId) {
  throw new Error("Set cloudflare accountId in sst.config.ts or CLOUDFLARE_ACCOUNT_ID in the environment");
}

Type guard

function hasCloudflareAccount(cfg: { accountId?: string }): boolean {
  return typeof cfg.accountId === "string" && cfg.accountId.length > 0;
}

Try / catch

try {
  await sst.deploy()
} catch (e) {
  if (String(e).includes("missing account")) {
    console.error("Set CLOUDFLARE_ACCOUNT_ID or provider accountId");
  }
}

Prevention

When it happens

Trigger: Configuring the Cloudflare provider without `accountId` in the sst.config.ts provider block and without `CLOUDFLARE_ACCOUNT_ID` in the environment; an API token lacking permission to list accounts so auto-detection fails.

Common situations: Using a user-scoped API token instead of an account-scoped one; forgetting to set `accountId` when the token belongs to multiple accounts.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30). Data as JSON: /api/errors/87e18ee99604fde4. Report an issue: GitHub.