t3-env issues with Vitest test cases
It looks like client environments are not being read. No issues with the server envs.

env.mjs
pnpm test doesnt see that skipValidation: !!process.env.SKIP_ENV_VALIDATION,skipValidation: !!process.env.SKIP_ENV_VALIDATION || !!import.meta.vitetestt3-complete repo that also uses Vitest?import { createEnv } from '@t3-oss/env-nextjs';
import { z } from 'zod';
export const env = createEnv({
server: {
NEXTAUTH_SECRET: z.string().min(1),
NEXTAUTH_URL: z.string().url(),
},
client: {
NEXT_PUBLIC_API_URL: z.string().url(),
},
runtimeEnv: {
// server
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
// client
NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL,
},
});import crypto from 'crypto';
import { describe, expect, it } from 'vitest';
import { z } from 'zod';
import { AuthResponseSchema } from '../auth';
describe('AuthResponseSchema', () => {
it('valid data passes', () => {
const data = {
id: crypto.randomUUID(),
token: 'validtoken',
};
expect(AuthResponseSchema.parse(data)).toEqual(data);
});
it('invalid data throws error', () => {
const data = {
id: 'invaliduuid',
token: '',
};
expect(() => AuthResponseSchema.parse(data)).toThrowError(z.ZodError);
});
}); ❯ onValidationError node_modules/.pnpm/@t3-oss+env-nextjs@0.3.1_typescript@5.0.4_zod@3.21.4/node_modules/@t3-oss/core/index.ts:128:13
❯ g node_modules/.pnpm/@t3-oss+env-nextjs@0.3.1_typescript@5.0.4_zod@3.21.4/node_modules/@t3-oss/core/index.ts:140:12
❯ Module.C node_modules/.pnpm/@t3-oss+env-nextjs@0.3.1_typescript@5.0.4_zod@3.21.4/node_modules/@t3-oss/env-nextjs/index.ts:28:10
❯ src/env.mjs:4:20
2| import { z } from 'zod';
3|
4| export const env = createEnv({
| ^
5| server: {
6| NEXTAUTH_SECRET: z.string().min(1),
❯ src/lib/api.ts:1:31import { env } from '@/env.mjs';
import axios, { type AxiosInstance } from 'axios';
/**
* An Axios instance with its base URL set to the API URL from the Sales middleware.
* @see https://code.notive.io/camera-tweedehands/sales-middleware-django
*
* @returns {AxiosInstance} An Axios instance.
*/
const api: AxiosInstance = axios.create({
baseURL: env.NEXT_PUBLIC_API_URL,
});
export default api;# Since the ".env" file is gitignored, you can use the ".env.example" file to
# build a new ".env" file when you clone the repo. Keep this file up-to-date
# when you add new variables to `.env`.
# This file will be committed to version control, so make sure not to have any
# secrets in it. If you are cloning this repo, create a copy of this file named
# ".env" and populate it with your secrets.
# When adding additional environment variables, the schema in "/src/env.mjs"
# should be updated accordingly.
# API
NEXT_PUBLIC_API_URL="http://localhost:8000/api"
# Next Auth
# You can generate a new secret on the command line with:
# openssl rand -base64 32
# https://next-auth.js.org/configuration/options#secret
NEXTAUTH_SECRET="UQzCUvyvDXxYKKVAPjuNy1D9td6G4b9XUmmqlAAzucE="
NEXTAUTH_URL="http://localhost:3000"import react from '@vitejs/plugin-react';
import tsconfigPaths from 'vite-tsconfig-paths';
import { defineConfig } from 'vitest/config';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [tsconfigPaths(), react()],
test: {
environment: 'jsdom',
},
});❌ Invalid environment variables: {
NEXTAUTH_SECRET: [ 'Required' ],
NEXTAUTH_URL: [ 'Required' ],
NEXT_PUBLIC_API_URL: [ 'Required' ]
}{
NEXTAUTH_SECRET: undefined,
NEXTAUTH_URL: undefined,
NEXT_PUBLIC_API_URL: undefined,
VITE_TEST_ENV: 'test'
}