Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to validate schema on build on next.config.ts #281

Open
fahmiidris opened this issue Nov 2, 2024 · 6 comments · May be fixed by #282
Open

how to validate schema on build on next.config.ts #281

fahmiidris opened this issue Nov 2, 2024 · 6 comments · May be fixed by #282

Comments

@fahmiidris
Copy link

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 on next.config.mjs.

does this need to be updated? and how to do it correctly and cleanly?

@jferrettiboke
Copy link

jferrettiboke commented Nov 2, 2024

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";

// ...

@chungweileong94
Copy link
Contributor

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 = {
  /** ... */
};

@jferrettiboke
Copy link

@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
Copy link
Contributor

chungweileong94 commented Nov 5, 2024

@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?

@phl23
Copy link

phl23 commented Nov 6, 2024

@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.

@jferrettiboke
Copy link

jferrettiboke commented Nov 7, 2024

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants