t3-env icon indicating copy to clipboard operation
t3-env copied to clipboard

Imports in next.config.ts is allowed in Next 15+

Open JulianKingman opened this issue 7 months ago • 6 comments

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

JulianKingman avatar May 07 '25 15:05 JulianKingman

Screenshot_20250531-172650~2.png

FleetAdmiralJakob avatar May 31 '25 15:05 FleetAdmiralJakob

Screenshot_20250531-172650~2.png

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"

juliansommer avatar Jun 03 '25 00:06 juliansommer

Does the env checking work too?

FleetAdmiralJakob avatar Jun 08 '25 15:06 FleetAdmiralJakob

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

sscotth avatar Jun 08 '25 17:06 sscotth

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! 🔥

Bartek532 avatar Jun 14 '25 08:06 Bartek532

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.

atimmer avatar Oct 14 '25 12:10 atimmer