Skip to content

[BUG]: varlock/auto-load succeeds silently with no .env.schema, while load and run fail #1143

Open

Description

@timche

varlock version

1.21.0

Steps to reproduce

In a directory with varlock installed but no .env.schema:

t.ts:

import "varlock/auto-load";
import { ENV } from "varlock/env";
console.log("API_URL =", (ENV as any).API_URL);
  1. varlock load
  2. varlock run -- sh -c 'echo child ran'
  3. bun t.ts

What is expected?

All three fail the same way, since there is nothing to load or validate.

What is actually happening?

1 and 2 exit 1 with "Run varlock init to create a .env.schema file, or use --path to specify a file or directory."

3 exits 0 and prints API_URL = undefined. varlock/auto-load succeeds silently, so validation is skipped and every ENV value is undefined.

Real ways to end up there: starting the app from a different working directory than the schema's, a monorepo package run from its own folder, or a build or archive that leaves the .env* files out (for example through export-ignore in .gitattributes). The app then starts with no config and fails later, far from the cause.

Suggested fix: make auto-load fail (or at least warn loudly) when no schema is found, like load and run, with an explicit opt-out for setups that rely on it.

System Info

macOS 27.0 (arm64)
Node v24.21.0
Bun 1.4.2
varlock 1.21.0

Any additional comments?

Found when a source-archive build ran with every value undefined because the archive excluded the schema files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions