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(next): next.config.ts #63051

Merged
merged 181 commits into from
Jul 9, 2024
Merged

Conversation

devjiwonchoi
Copy link
Member

@devjiwonchoi devjiwonchoi commented Mar 8, 2024

Note: port of #57656

What?

This PR initiated support of next.config.ts.

Follow ups:

  • update docs (x-ref)
  • update cna ts templates (x-ref)

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

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:

  • export default
  • export config as default
  • config as an async function
  • use Node.js modules (fs, path, etc.)
  • HMR on config change
  • throw when type error
  • turbopack

Importing Files

  • nested imports (config -> A -> B)
  • import alias (tsconfig baseUrl and paths)
  • import from node_modules
  • import JSON

Extensions

  • .ts
  • .cts
  • .mts
  • .cjs
  • .mjs
  • .js (both ESM and CJS w/o extra change)

devjiwonchoi and others added 30 commits October 27, 2023 12:15
ref: vercel#57656 (comment)

Co-authored-by: Donny/강동윤 <kdy1997.dev@gmail.com>
Co-authored-by: rodrigo
<falsepopsky@protonmail.com>
Co-authored-by: Sukka <isukkaw@gmail.com>
@devjiwonchoi devjiwonchoi marked this pull request as ready for review July 8, 2024 19:40
@devjiwonchoi devjiwonchoi requested a review from ijjk July 9, 2024 03:18
@ijjk
Copy link
Member

ijjk commented Jul 9, 2024

Amazing work, thank you!

@devjiwonchoi devjiwonchoi merged commit dad4c32 into vercel:canary Jul 9, 2024
82 checks passed
@devjiwonchoi devjiwonchoi deleted the next-config-ts-esm branch July 9, 2024 17:41
export const CONFIG_FILES = [
'next.config.js',
'next.config.mjs',
'next.config.ts',
Copy link
Contributor

Choose a reason for hiding this comment

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

If .mjs is supported, then why not .mts too?

Copy link
Member Author

@devjiwonchoi devjiwonchoi Jul 10, 2024

Choose a reason for hiding this comment

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

You can handle native ESM in CJS project with next.config.ts, no need for next.config.mts, it should work.

Extensions

  • .ts
  • .cts
  • .mts
  • .cjs
  • .mjs
  • .js (both ESM and CJS w/o extra change)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CI approved Approve running CI for fork create-next-app Related to our CLI tool for quickly starting a new Next.js application. created-by: Next.js team PRs by the Next.js team Documentation Related to Next.js' official documentation. locked tests type: next
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet