Support @t3-oss/env-nextjs and zod in runtime

The t3 stack is a very popular tool among the typescript community.

It comes with validated env support. We got a env.e2e.ts file for our playwright tests and we busy setting up checkly, but right now it means we cant use this validated env file and need to switch to process.env.* the old fashioned way. If you could support those 2 packages at runtime, that would be fantastic!

See our env.e2e.ts file below

/* eslint-disable @typescript-eslint/no-var-requires */
import { createEnv } from '@t3-oss/env-nextjs'
import { z } from 'zod'

// This is needed in test environment, but not nextjs
require('dotenv').config()

export const env = createEnv({
  /**
   * Specify your playwright environment variables schema here.
   */
  server: {
    NODE_ENV: z.enum(['test']),
    BASE_URL: z.string().url().default('http://localhost:3000'),
    TEST_USER_EMAIL: z.string().email(),
    TEST_USER_PASSWORD: z.string().min(8),
    CI: z
      .string()
      .optional()
      .transform((value) => value === 'true'),
  },

  runtimeEnv: process.env as Record<string, string | boolean>,

  onInvalidAccess: (variable) => {
    throw new Error(`Invalid access of env variable: ${variable}`)
  },
})

Please authenticate to join the conversation.

Upvoters
Status

Completed

Board

πŸ’‘ Feature Request

Tags

Runtimes

ETA
Sep 21, 2023
Date

Over 2 years ago

Author

Pieter Venter

Subscribe to post

Get notified by email when there are changes.