Skip to content

BUG: .env files needs moving from apps folder to packages/env #761

Closed

Description

@moreorover

Reproducible:

pnpm create better-t-stack@latest my-better-t-app-check --frontend tanstack-router --backend hono --runtime node --database postgres --orm drizzle --api trpc --auth better-auth --payments none --addons oxlint turborepo --examples todo --db-setup docker --web-deploy none --server-deploy none --git --package-manager pnpm --install

This error has been introduced with #755

When running dev server locally server results in:

> server@ dev /Users/mselvenis/dev/my-better-t-app-check/apps/server
> tsx watch src/index.ts

❌ Invalid environment variables: [
  {
    expected: 'string',
    code: 'invalid_type',
    path: [ 'DATABASE_URL' ],
    message: 'Invalid input: expected string, received undefined'
  },
  {
    expected: 'string',
    code: 'invalid_type',
    path: [ 'BETTER_AUTH_SECRET' ],
    message: 'Invalid input: expected string, received undefined'
  },
  {
    expected: 'string',
    code: 'invalid_type',
    path: [ 'BETTER_AUTH_URL' ],
    message: 'Invalid input: expected string, received undefined'
  },
  {
    expected: 'string',
    code: 'invalid_type',
    path: [ 'CORS_ORIGIN' ],
    message: 'Invalid input: expected string, received undefined'
  }
]
/Users/mselvenis/dev/my-better-t-app-check/node_modules/.pnpm/@t3-oss+env-core@0.13.10_typescript@5.9.3_zod@4.2.1/node_modules/@t3-oss/env-core/src/index.ts:365
      throw new Error("Invalid environment variables");
            ^

Error: Invalid environment variables
    at <anonymous> (/Users/mselvenis/dev/my-better-t-app-check/node_modules/.pnpm/@t3-oss+env-core@0.13.10_typescript@5.9.3_zod@4.2.1/node_modules/@t3-oss/env-core/src/index.ts:365:13)
    at createEnv (/Users/mselvenis/dev/my-better-t-app-check/node_modules/.pnpm/@t3-oss+env-core@0.13.10_typescript@5.9.3_zod@4.2.1/node_modules/@t3-oss/env-core/src/index.ts:375:12)
    at <anonymous> (/Users/mselvenis/dev/my-better-t-app-check/packages/env/src/server.ts:4:20)
    at ModuleJob.run (node:internal/modules/esm/module_job:377:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:691:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5)

Activity

  1. AmanVarshney01 commented on Dec 26, 2025

    @AmanVarshney01
    Owner

    Thanks for this. I completely forgot to check for pnpm. Since Bun automatically loads the env, everything worked in my testing.

    I’ve added dotenv in server.ts to ensure the env is loaded when using pnpm or npm.

  2. moreorover commented on Dec 26, 2025

    @moreorover
    ContributorAuthor

    closed with #762

  3. Repository owner deleted a comment from coderabbitai on Dec 26, 2025
  4. Repository owner deleted a comment from linear on Dec 26, 2025
  5. jroth1111 commented on Jan 2, 2026

    @jroth1111

    FYI: I opened a consolidated Cloudflare env injection proposal that references this issue and suggests a root .dev.vars + explicit Wrangler bindings flow: #787

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions