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

feat: Use TypeScript Next.js config (next.config.ts) #2082

Open
martin-eq opened this issue Mar 23, 2025 · 2 comments
Open

feat: Use TypeScript Next.js config (next.config.ts) #2082

martin-eq opened this issue Mar 23, 2025 · 2 comments
Labels
🌟 enhancement New feature or request

Comments

@martin-eq
Copy link

Is your feature request related to a problem? Please describe.

It would be great to use TS as much as possible in the project, right now we are using env.js file because we import it in next.config.js

Newer versions of Next.js seem to support ESM in next.config.ts file.

Describe the solution you'd like to see

I suggest migrating from next.config.js to next.config.ts and to be able to convert env.js to env.ts as well.

Describe alternate solutions

The alternative is to continue using JS files with TS definitions in comments, but I don't think this is the cleaner approach.

Additional information

No response

@juliusmarminge
Copy link
Member

Newer versions of Next.js seem to support ESM in next.config.ts file.

You have a source on this? Still fails on 15.2.4 for me when using ESM-only stuff:

Image

@BinarySenseiii
Copy link

BinarySenseiii commented Apr 3, 2025

`
async function createNextConfig(): Promise {
const { createJiti } = await import('jiti')
const jiti = createJiti(fileURLToPath(import.meta.url))

// Import env or other files here, within the async function
await jiti.import('./src/constants/env.ts')

return {}, // next js configuration
}
}

export default (async () => withBundleAnalyzer(await createNextConfig()))()
`

here's the workaround... https://github.com/BinarySenseiii/next-clean/blob/main/next.config.ts
@martin-eq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟 enhancement New feature or request
Projects
None yet
3 participants