Skip to content

feat: support next.config.ts #50126

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

Closed
wants to merge 19 commits into from

Conversation

helbing
Copy link

@helbing helbing commented May 21, 2023

This PR is to support next.config.ts, related to discusses #50121

@helbing
Copy link
Author

helbing commented May 28, 2023

@ijjk Can you review this PR?

@vercel-spaces
Copy link

vercel-spaces bot commented Jun 28, 2023

Notifying the following users due to files changed in this PR:

@timneutkens, @ijjk, @shuding, @styfle, @huozhi:

packages/next/src/server/config.ts

This comment was posted based on the notify modifier.

@joulev
Copy link
Contributor

joulev commented Jul 13, 2023

Could this PR be reviewed?

Copy link
Member

@timneutkens timneutkens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is introducing additional dependencies, e.g. jiti and sucrase and causes a divergence between how TypeScript is handled in next.config.ts and the application, these should be the same as otherwise application code will behave differently. I.e. you'll have to run webpack on the next.config.ts with the same configuration as the application code and then run the require on the output bundle.

devjiwonchoi added a commit that referenced this pull request Jul 9, 2024
> Note: port of #57656

## What?

This PR initiated support of `next.config.ts`.

Follow ups:

- update docs
([x-ref](2ea9b6e))
- update cna ts templates
([x-ref](80e6740))

## Why?

> Next.js provides a TypeScript-first development experience for
building your React application.

This PR can resolve the two main needs:

1. Import TS files to the config.
2. Conduct a type check directly by importing `type` instead of JSDoc.

x-ref: #5318 #35969 #44632 #50121 #50126

## How?

### Goals

- [x] [do not
bundle](#57656 (comment))
- [x] [minimum fs
operations](#63051 (comment))
- [x] zero restrictions

Used `require.extensions` hooks to transpile the imported files on the
fly.

To reduce I/O operation on disk, used custom `module.exports` to require
directly from a transpiled code string.

## Expected

> Added tests for the cases below:

- [x] export default
- [x] export config `as default`
- [x] [config as an async
function](https://nextjs.org/docs/app/api-reference/next-config-js)
- [x] use Node.js modules (fs, path, etc.)
- [x] HMR on config change
- [x] throw when type error
- [x] turbopack

### Importing Files

- [x] nested imports (config -> A -> B)
- [x] import alias (tsconfig baseUrl and paths)
- [x] import from `node_modules`
- [x] import `JSON`

#### Extensions

- [x] `.ts`
- [x] `.cts`
- [x] `.mts`
- [x] `.cjs`
- [x] `.mjs`
- [x] `.js` (both ESM and CJS w/o extra change)

---------

Co-authored-by: Donny/강동윤 <[email protected]>
Co-authored-by: Sukka <[email protected]>
Co-authored-by: JJ Kasper <[email protected]>
Co-authored-by: Sam Ko <[email protected]>
Co-authored-by: Ahmed Abdelbaset <[email protected]>
Co-authored-by: JJ Kasper <[email protected]>
@devjiwonchoi
Copy link
Member

Closing due to #63051, thank you for the PR!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants