Installation
Learn how to create a new Next.js application with the `create-next-app` CLI, and set up TypeScript, ESLint, and Module Path Aliases.
System requirements
Before you begin, make sure your system meets the following requirements:
- Node.js 20.9 or later.
- macOS, Windows (including WSL), or Linux.
Create with the CLI
The quickest way to create a new Next.js app is using create-next-app, which sets up everything automatically for you. To create a project, run:
On installation, you'll see the following prompts:
If you choose to customize settings, you'll see the following prompts:
After the prompts, create-next-app will create a folder with your project name and install the required dependencies.
Manual installation
To manually create a new Next.js app, install the required packages:
Good to know: The App Router uses React canary releases built-in, which include all the stable React 19 changes, as well as newer features being validated in frameworks. The Pages Router uses the React version you install in package.json.
Then, add the following scripts to your package.json file:
These scripts refer to the different stages of developing an application:
next dev: Starts the development server using Turbopack (default bundler).next build: Builds the application for production.next start: Starts the production server.eslint: Runs ESLint.
Turbopack is now the default bundler. To use Webpack run next dev --webpack or next build --webpack. See the Turbopack docs for configuration details.
Create the pages directory
Next.js uses file-system routing, which means the routes in your application are determined by how you structure your files.
Create a pages directory at the root of your project. Then, add an index.tsx file inside your pages folder. This will be your home page (/):
Next, add an _app.tsx file inside pages/ to define the global layout. Learn more about the custom App file.
Finally, add a _document.tsx file inside pages/ to control the initial response from the server. Learn more about the custom Document file.
Create the public folder (optional)
Create a public folder at the root of your project to store static assets such as images, fonts, etc. Files inside public can then be referenced by your code starting from the base URL (/).
You can then reference these assets using the root path (/). For example, public/profile.png can be referenced as /profile.png:
Run the development server
- Run
npm run devto start the development server. - Visit
http://localhost:3000to view your application. - Edit the
pages/index.tsxfile and save it to see the updated result in your browser.
Set up TypeScript
Minimum TypeScript version: v5.1.0
Next.js comes with built-in TypeScript support. To add TypeScript to your project, rename a file to .ts / .tsx and run next dev. Next.js will automatically install the necessary dependencies and add a tsconfig.json file with the recommended config options.
See the TypeScript reference page for more information.
Set up linting
Next.js supports linting with either ESLint or Biome. Choose a linter and run it directly via package.json scripts.
- Use ESLint (comprehensive rules):
- Or use Biome (fast linter + formatter):
If your project previously used next lint, migrate your scripts to the ESLint CLI with the codemod:
If you use ESLint, create an explicit config (recommended eslint.config.mjs). ESLint supports both the legacy .eslintrc.* and the newer eslint.config.mjs formats. See the ESLint API reference for a recommended setup.
Good to know: Starting with Next.js 16, next build no longer runs the linter automatically. Instead, you can run your linter through NPM scripts.
See the ESLint Plugin page for more information.
Set up Absolute Imports and Module Path Aliases
Next.js has in-built support for the "paths" and "baseUrl" options of tsconfig.json and jsconfig.json files.
These options allow you to alias project directories to absolute paths, making it easier and cleaner to import modules. For example:
To configure absolute imports, add the baseUrl configuration option to your tsconfig.json or jsconfig.json file. For example:
In addition to configuring the baseUrl path, you can use the "paths" option to "alias" module paths.
For example, the following configuration maps @/components/* to components/*:
Each of the "paths" are relative to the baseUrl location.