Capítulo 287 de 456
How to create a new Next.js app with the Pages Router, either via create-next-app or manual setup, including TypeScript, linting, and import aliases.
create-next-app: scaffolds a full project; recommended defaults are TypeScript, ESLint, Tailwind CSS, App Router, AGENTS.md (note: default steers toward App Router even though this page documents Pages Router manual setup).pages directory: file-system routing root for the Pages Router; pages/index.tsx = /._app.tsx: custom App file defining the global layout wrapper ({ Component, pageProps })._document.tsx: custom Document file controlling the initial server HTML response (<Html>, <Head />, <Main />, <NextScript />).next typegen: (cross-referenced) generates next-env.d.ts and route types; also produced automatically by next dev/next build.package.json scripts; next lint is gone as of Next.js 16 (next build no longer auto-lints).tsconfig.json/jsconfig.json baseUrl + paths.next upgrade: keeps the app current; also refreshes bundled docs at node_modules/next/dist/docs/ so AI coding agents reflect the installed version.export default function Page() {
return <h1>Hello, Next.js!</h1>
}
import type { AppProps } from 'next/app'
export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
import { Html, Head, Main, NextScript } from 'next/document'
export default function Document() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "eslint",
"lint:fix": "eslint --fix"
}
}
{
"compilerOptions": {
"baseUrl": "src/",
"paths": {
"@/styles/*": ["styles/*"],
"@/components/*": ["components/*"]
}
}
}
index, _app, _document) e a configuração de alias de import.| Script | Purpose |
|---|---|
next dev | Dev server (Turbopack default) |
next build | Production build |
next start | Production server |
eslint | Lint |
next lint scripts after upgrading to Next.js 16: next build no longer runs the linter automatically; migrate with npx @next/codemod@canary next-lint-to-eslint-cli ..~ import syntax expecting linting to catch stale scripts: unrelated but a reminder that migration codemods exist for exactly these breaking changes.create-next-app's "recommended defaults" push toward App Router; Pages Router requires either the customize-settings flow or manual installation as shown here.pages/index.tsx, pages/_app.tsx, pages/_document.tsx (the last one optional but common)..ts/.tsx and run next dev — Next.js installs deps and writes tsconfig.json automatically.next upgrade is not just a version bump — it refreshes the docs bundled with the package, which downstream AI agents read from disk.next dev/build/start/upgrade/typegen.