withastro/astro · warning

Unable to read wrangler config, variables defined in it…

Error message

Unable to read wrangler config, variables defined in it will not be available to astro:env at build time.

What it means

The Cloudflare adapter reads your wrangler config (wrangler.toml / wrangler.jsonc) to copy its `vars` entries into process.env so astro:env variables resolve at build time. The whole read runs in a try/catch; any throw — missing file, unreadable, invalid TOML/JSONC, unexpected shape — logs this warning and continues, with the original error only visible via logger.debug.

Solutions

  1. Create or repair the wrangler config at the project root and fix the syntax error
  2. Confirm it parses with Wrangler itself: `npx wrangler deploy --dry-run --outdir /tmp/cf-dry` (or `npx wrangler types`) exits cleanly
  3. Re-run with debug logging (e.g. ASTRO_LOG_LEVEL=debug) to see the swallowed exception
  4. Mirror build-critical vars in properly scoped .env files so builds do not depend solely on wrangler config

Example fix

# before: wrangler.toml invalid (unclosed table)
name = "site"
[vars
PUBLIC_API_URL = "https://api.example.com"

# after: valid config
name = "site"
compatibility_date = "2025-01-01"

[vars]
PUBLIC_API_URL = "https://api.example.com"
Defensive patterns

Strategy: validation

Validate before calling

# Validate the wrangler config before building
npx wrangler types || npx wrangler deploy --dry-run --outdir /tmp/cf-dry-run

Prevention

When it happens

Trigger: The wrangler config is absent (never created, renamed, or not checked out in CI), syntactically invalid after editing bindings, or lives where the adapter does not look. Afterwards, every astro:env variable defined only in wrangler `vars` is undefined during the build.

Common situations: Renaming wrangler.toml to wrangler.jsonc mid-migration and leaving broken syntax; CI jobs that skip copying the config; developers who run builds without Wrangler installed and never validate the file.

Related errors


AI-assisted analysis of withastro/astro@52e6c34790 (2026-08-18). Data as JSON: /api/errors/948be2a324754452. Report an issue: GitHub.

Appendix: source

Thrown at packages/integrations/cloudflare/src/utils/wrangler-config.ts:68

			config.configPath,
			undefined,
			config.vars,
			env,
			true,
			config.secrets,
		);

		for (const [key, binding] of Object.entries(vars)) {
			// `vars` can hold non-string JSON values (numbers, booleans, objects).
			// `process.env` only stores strings.
			const value = binding.value;
			if (value === undefined || value === null) {
				continue;
			}
			process.env[key] = typeof value === 'string' ? value : JSON.stringify(value);
		}
	} catch (e) {
		logger.warn(
			`Unable to read wrangler config, variables defined in it will not be available to astro:env at build time.`,
		);
		logger.debug(String(e));
	}
}

View on GitHub (pinned to 52e6c34790)