Imports in next.config.ts is allowed in Next 15+
As I was setting up t3-env in my latest project, I noticed that Next 15 now supports imports in next.config.ts, no jiti required.
source: https://github.com/vercel/next.js/discussions/35969#discussioncomment-10005034
PR for docs update: https://github.com/t3-oss/t3-env/pull/342
they updated it recently so you can import esm modules in next.config.ts. just must not have updated the docs but it definitely does work.
in my next.config.ts I just do this
import "./src/env"
Does the env checking work too?
Support ES module format (ESM) in next.config.js #32239
@FleetAdmiralJakob Yes, I get env checking during build with import "./src/env"
bun run build
$ next build
❌ Invalid environment variables: [
{
code: 'invalid_type',
expected: 'string',
received: 'undefined',
path: [ 'DATABASE_URL' ],
message: 'Required'
}
]
⨯ Failed to load next.config.ts, see more info here https://nextjs.org/docs/messages/next-config-error
> Build error occurred
Error: Invalid environment variables
at Object.<anonymous> (src/lib/env.ts:13:36)
error: script "build" exited with code 1
Hey!
I just released a library that might be a great fit for your use case - it's a drop-in replacement for the one you're currently using, with some extra features like a built-in CLI and live preview:
🔗 https://envin.turbostarter.dev/
Feel free to reach out if you have any questions or suggestions - every bit of feedback is welcome! 🔥
Support ES module format (ESM) in next.config.js #32239
@FleetAdmiralJakob Yes, I get env checking during build with
import "./src/env"
I can confirm that this also works for us. Using Next.js 15.5.3.