Closed FleetAdmiralJakob closed 3 months ago
I don't know if I'm doing this right, but here is what I did and is working:
env.ts
file with my environment variables schema:import { createEnv } from "@t3-oss/env-core"
import { z } from "zod"
export const env = createEnv({
clientPrefix: "EXPO_PUBLIC_",
client: {
EXPO_PUBLIC_GOOGLE_MAPS_API_KEY: z.string().min(1),
EXPO_PUBLIC_API_BASE_URL: z.string().url(),
},
runtimeEnv: {
EXPO_PUBLIC_GOOGLE_MAPS_API_KEY:
process.env.EXPO_PUBLIC_GOOGLE_MAPS_API_KEY,
EXPO_PUBLIC_API_BASE_URL: process.env.EXPO_PUBLIC_API_BASE_URL,
},
})
.env
file that contains all my environment variables with fake values: this file is versioned as a reference for all the environment variables that should be filled in the project.env.local
file that contains the environment variables with real values: this file in git ignoredThen use the env
object
import { env } from "@/env"
env.EXPO_PUBLIC_GOOGLE_MAPS_API_KEY
I hope it helps!
also, I found a typescript issue when importing, so I added:
"@t3-oss/env-core": ["./node_modules/@t3-oss/env-core/dist/index.d.ts"]
to the paths
section in tsconfig.json
:
{
"extends": "expo/tsconfig.base",
"compilerOptions": {
"strict": true,
"module": "ESNext",
"paths": {
"@t3-oss/env-core": ["./node_modules/@t3-oss/env-core/dist/index.d.ts"]
}
},
"include": ["**/*.ts", "**/*.tsx"]
}
also, I found a typescript issue when importing, so I added:
That's most likely related to a bad moduleResolution setting in your tsconfig (or the expo base config you're extending from) See #189, #190, #191, #195 etc
I saw that this library supports expo but does not know how to implement it.