-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
Comments
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 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. |
Can you provide a small repo for it? |
@jferrettiboke 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: 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; |
I'm encountering experimental warnings when running Environment:
When I switch to the latest Node.js version (v23), the warnings are gone. But I prefer to use the LTS version rather than the latest version. Is there any way silence or suppress these warnings without switching from the LTS version to latest version of Node.js? env.ts
import { createEnv } from '@t3-oss/env-nextjs'
import { z } from 'zod'
export const env = createEnv({
server: {
DATABASE_URL: z.string().url(),
},
experimental__runtimeEnv: process.env,
}) next.config.ts
import type { NextConfig } from 'next';
import '@/lib/env';
const nextConfig: NextConfig = {};
export default nextConfig; Output: bun dev
$ next dev --turbopack
(node:42916) ExperimentalWarning: CommonJS module /../src/lib/env.ts is loading ES Module /../node_modules/@t3-oss/env-nextjs/dist/index.js using require().
Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
▲ Next.js 15.1.2 (Turbopack)
- Local: http://localhost:3000
- Network: http://10.0.19.188:3000
- Environments: .env |
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?
The text was updated successfully, but these errors were encountered: