T3 env with next.config.ts in v15.0.0-canary.179
Unanswered
American Fuzzy Lop posted this in #help-forum
American Fuzzy LopOP
Hi
I'm trying to use T3 env https://env.t3.gg/docs/nextjs in my config.next.ts but it gives me error I also try to use it without "jiti" but it does not work and server do not start
I use bun in my project
my next config code
===================
and my src/env/server.ts code
===========================
I'm trying to use T3 env https://env.t3.gg/docs/nextjs in my config.next.ts but it gives me error I also try to use it without "jiti" but it does not work and server do not start
I use bun in my project
my next config code
===================
import type { NextConfig } from "next";
import { env } from "@/env/server";
const nextConfig: NextConfig = {
experimental: {
typedRoutes: true,
},
env: {
...env,
},
};
export default nextConfig;and my src/env/server.ts code
===========================
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";
export const env = createEnv({
server: {
NODE_ENV: z.enum(["development", "production"]),
},
emptyStringAsUndefined: true,
experimental__runtimeEnv: process.env,
});13 Replies
@American Fuzzy Lop Hi
I'm trying to use T3 env https://env.t3.gg/docs/nextjs in my config.next.ts but it gives me error I also try to use it without "jiti" but it does not work and server do not start
I use bun in my project
my next config code
===================
TS
import type { NextConfig } from "next";
import { env } from "@/env/server";
const nextConfig: NextConfig = {
experimental: {
typedRoutes: true,
},
env: {
...env,
},
};
export default nextConfig;
and my src/env/server.ts code
===========================
TS
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";
export const env = createEnv({
server: {
NODE_ENV: z.enum(["development", "production"]),
},
emptyStringAsUndefined: true,
experimental__runtimeEnv: process.env,
});
No issues for me if you follow the docs and use jiti, it's a built in module so you don't even have the install it
American Fuzzy LopOP
Is there a way to use this with next.config.ts?
@American Fuzzy Lop Is there a way to use this with next.config.ts?
afaik, no because next.config.ts is still too new so the lib hasn't been updated to support that currently.
@American Fuzzy Lop Hi
I'm trying to use T3 env https://env.t3.gg/docs/nextjs in my config.next.ts but it gives me error I also try to use it without "jiti" but it does not work and server do not start
I use bun in my project
my next config code
===================
TS
import type { NextConfig } from "next";
import { env } from "@/env/server";
const nextConfig: NextConfig = {
experimental: {
typedRoutes: true,
},
env: {
...env,
},
};
export default nextConfig;
and my src/env/server.ts code
===========================
TS
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";
export const env = createEnv({
server: {
NODE_ENV: z.enum(["development", "production"]),
},
emptyStringAsUndefined: true,
experimental__runtimeEnv: process.env,
});
it works just fine for me https://github.com/joulev/debug/tree/nextjs-config-ts-with-t3-env. you never specified any error messages so it's impossible to know what's wrong on your side.
by the way, why did you add the
btw even with using
env config? it's deprecated and you should just consider it gone. https://nextjs.org/docs/app/api-reference/next-config-js/env,Good to know: environment variables specified in this way will always be included in the JavaScript bundle, prefixing the environment variable name withNEXT_PUBLIC_only has an effect when specifying them through the environment or .env files.
btw even with using
env in the config object, my example above still works.@joulev it works just fine for me https://github.com/joulev/debug/tree/nextjs-config-ts-with-t3-env. you never specified any error messages so it's impossible to know what's wrong on your side.
That's nice to know, do you know what canary release included
next.config.ts I missed that release?@joulev [#63051](<https://github.com/vercel/next.js/pull/63051>), v15.0.0-canary.60
Oh damn it was a while ago, probably why I missed it. Joined the canary train in late august.
Yeah I just switched to using
next.config.ts and no issues for me either.American Fuzzy LopOP
actually i enable the organizeImports on my .vscode/setting.json file which automatically delete my ENV import in next-config.ts because it's not used so there is any way to disable this setting on a specific file ?
"editor.codeActionsOnSave": {
"source.organizeImports": "always"
},