nextjs
> TypeScript configuration for Next.js apps (App Router and Pages Router). Extends @jmlweb/tsconfig-react with incremental builds, the Next.js plugin and an @/* alias.
โจ Features
Section titled โโจ Featuresโ- ๐ Next.js Plugin: enhanced type checking for Next.js APIs
- โก Incremental Builds:
incremental: truefor faster rebuilds - ๐ Path Alias:
@/*maps to the project root - โ๏ธ React Ready: inherits JSX, DOM types and bundler resolution
- ๐ Strict Mode: inherits every strict flag from the base config
๐ฆ Installation
Section titled โ๐ฆ Installationโnpm install --save-dev @jmlweb/tsconfig-nextjs @jmlweb/tsconfig-react @jmlweb/tsconfig-base next typescript๐ Quick Start
Section titled โ๐ Quick Startโ{ "extends": "@jmlweb/tsconfig-nextjs", "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], "exclude": ["node_modules"]}๐ก Examples
Section titled โ๐ก ExamplesโPages Router
Section titled โPages Routerโ{ "extends": "@jmlweb/tsconfig-nextjs", "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], "exclude": ["node_modules"]}src/ directory with custom aliases
Section titled โsrc/ directory with custom aliasesโOverriding paths replaces the default @/* entry.
{ "extends": "@jmlweb/tsconfig-nextjs", "compilerOptions": { "paths": { "@/*": ["./src/*"], "@/components/*": ["./src/components/*"] } }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], "exclude": ["node_modules"]}๐ Configuration Details
Section titled โ๐ Configuration DetailsโExtends @jmlweb/tsconfig-react (which extends @jmlweb/tsconfig-base) and adds:
| Option | Value | Description |
|---|---|---|
incremental |
true |
Reuse previous compilation info |
plugins |
[{ "name": "next" }] |
Next.js TypeScript plugin |
paths |
{ "@/*": ["./*"] } |
@/* alias pointing to project root |
Inherited from the React config: jsx: "react-jsx", module: "ESNext", moduleResolution: "bundler", lib: ["ES2022", "DOM", "DOM.Iterable"].
incremental writes a .tsbuildinfo file; add it to .gitignore.
๐ฏ When to Use
Section titled โ๐ฏ When to Useโ- โ Next.js apps with the App Router or Pages Router
- โ
Projects that want the
@/*import convention
Plain React: use @jmlweb/tsconfig-react.
๐ง Extending the Configuration
Section titled โ๐ง Extending the Configurationโ{ "extends": "@jmlweb/tsconfig-nextjs", "compilerOptions": { "noEmit": true, "paths": { "~/*": ["./src/*"] } }}๐ Usage with Scripts
Section titled โ๐ Usage with Scriptsโ{ "scripts": { "dev": "next dev", "build": "next build", "typecheck": "tsc --noEmit" }}npm run typecheck๐ Requirements
Section titled โ๐ Requirementsโ- Node.js >= 22.12.0
- TypeScript >= 5.0.0
- Next.js >= 13.0.0
๐ฆ Peer Dependencies
Section titled โ๐ฆ Peer Dependenciesโ@jmlweb/tsconfig-react(^2.0.0), which itself requires@jmlweb/tsconfig-base(^2.0.0)next(>=13.0.0)typescript(>=5.0.0)
๐ Related Packages
Section titled โ๐ Related Packagesโ@jmlweb/tsconfig-react- config extended by this package@jmlweb/tsconfig-base- root of the extends chain@jmlweb/oxlint-config-react- Oxlint configuration for React (recommended)@jmlweb/oxfmt-config-base- Oxfmt configuration (recommended)
๐ Migration Guide
Section titled โ๐ Migration Guideโ1.x โ 2.0.0
Section titled โ1.x โ 2.0.0โBreaking: Node.js >=22.12.0 is now required (Node.js 18 and 20 are end-of-life).
- Upgrade Node.js to 22.12.0 or later.
- Update the package:
npm install --save-dev @jmlweb/tsconfig-nextjs@^2.0.0.
The compilerOptions are unchanged. See the Changelog.
๐ License
Section titled โ๐ LicenseโMIT