Open fahmiidris opened 1 week ago
Yeah, I'm interested in this too.
I'm trying something like the following, but it doesn't seem to work.
import { env as clientEnv } from "@/lib/env/client";
import { env as serverEnv } from "@/lib/env/server";
// ...
I already submitted a PR for this, so basically, it is as simple as just importing the env file in next.config.ts
.
import type { NextConfig } from "next";
// Import env here to validate during build.
import "./app/env";
const nextConfig: NextConfig = {
/** ... */
};
@chungweileong94 I am already importing it into my next.config.ts file and it doesn’t work for me. See my previous comment.
I am using Next.js 15 canary with the turbo flag.
@chungweileong94 I am already importing it into my next.config.ts file and it doesn’t work for me. See my previous comment.
I am using Next.js 15 canary with the turbo flag.
Can you provide a small repo for it?
@jferrettiboke I'm using Next,js 15 with turbo and just importing, as @chungweileong94 said, worked for me.
I renamed next.config.js to next.config.ts and env.js to env.ts. (the latter is not necessary here, I think)
In next.config.ts:
replace this: await import("./src/env.js");
with this: import "./src/env";
Check that we don't use import()
here!
Of course you use own path like ./app or else.
Thanks @chungweileong94 @phl23! I was importing in another way. It now works for me.
Before:
import type { NextConfig } from "next";
import { env as clientEnv } from "@/lib/env/client";
import { env as serverEnv } from "@/lib/env/server";
const nextConfig: NextConfig = {
/* config options here */
};
export default nextConfig;
After:
import type { NextConfig } from "next";
import "@/lib/env/client";
import "@/lib/env/server";
const nextConfig: NextConfig = {
/* config options here */
};
export default nextConfig;
Next.js config now support
.ts
, and in this documentation https://env.t3.gg/docs/nextjs#validate-schema-on-build-(recommended) need jiti to load.ts
onnext.config.mjs
.does this need to be updated? and how to do it correctly and cleanly?