fix: load .env in standalone tsx scripts
CI / check (push) Successful in 25s
CI / release (push) Skipped
CI / deploy (push) Successful in 52s

This commit is contained in:
openhands committed 2026-08-11 17:08:23 +02:00
1 parent 0c39405dab
commit abc06e438c
3 files changed
+21

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
import "./load-env";
import { readdirSync, readFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
+1
View File
@@ -1,3 +1,4 @@
import "./load-env";
import { Cron } from "croner";
import { lt, sql } from "drizzle-orm";
import { env } from "../src/env";
+19
View File
@@ -0,0 +1,19 @@
import { existsSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const ROOT = resolve(__dirname, "..");
// Standalone scripts (tsx) don't auto-load .env like Next.js does, so the
// deploy step symlinks ${LIVE}/.env into the stage but nothing ever read it.
// Node's loadEnvFile() never overrides already-set variables, so real shell
// env wins; we load .env.local first so it takes precedence over .env.
function loadEnvFile(): void {
for (const name of [".env.local", ".env"]) {
const file = resolve(ROOT, name);
if (existsSync(file)) process.loadEnvFile(file);
}
}
loadEnvFile();