IntelliJ IDEA 2025.1 Help

Next.js

IntelliJ IDEA integrates with the Next.js React framework.

Before you start

  1. Download and install Node.js.

  2. Make sure the JavaScript and TypeScript and Next.js Support required plugins are enabled on the Settings | Plugins page, tab Installed. For more information, refer to Managing plugins.

Create a new Next.js application

The recommended way to start building a new Next.js application is the create-next-app package, which IntelliJ IDEA downloads and runs for you using npx. As a result, your development environment is preconfigured to use Next.js.

Of course, you can still download create-next-app yourself or create an empty IntelliJ IDEA project and install Next.js in it.

Generate a Next.js application with create-next-app

  1. Select File | New | Project from the main menu or click the New Project button on the Welcome screen.

  2. In the New Project dialog, select React in the left-hand pane.

  3. In the right-hand part of the wizard, specify the project name and the folder to create it in.

  4. In the Project type area, select Next.js.

    In the Node Interpreter field, specify the Node.js interpreter to use. Select a configured interpreter from the list or choose Add to configure a new one.

    From the create-next-app list, select npx create-next-app.

    Alternatively, for npm version 5.1 and earlier, install the create-next-app package yourself by running npm install --save-dev next react react-dom in the Terminal Alt+F12. When creating an application, select the folder where the create-next-app package is stored.

  5. Optionally:

    To use TypeScript instead of JavaScript, select the Use TypeScript template checkbox. IntelliJ IDEA will generate .ts files for your application and a tsconfig.json configuration file.

  6. When you click Create, IntelliJ IDEA generates a Next.js-specific project with all the required configuration files and downloads the required dependencies. IntelliJ IDEA also creates an npm start and JavaScript Debug configurations with default settings for running or debugging your application.

Install Next.js in an empty IntelliJ IDEA project

In this case, you will have to configure the build pipeline yourself. Learn more about adding Next.js to a project from the Next.js official website.

Create an empty IntelliJ IDEA project

  1. Select File | New | Project from the main menu or click the New Project button on the Welcome screen.

  2. In the New Project dialog, select New Project in the left-hand pane.

  3. In the right-hand pane, select JavaScript in the Language area.

  4. Name the new project and change its location if necessary, then click Create.

Install Next.js in an empty project

  1. Open the empty project where you will use Next.js.

  2. In the embedded Terminal (Alt+F12) , type:

    npm install --save-dev next react react-dom

Start with an existing Next.js application

To continue developing an existing Next.js application, open it in IntelliJ IDEA and download the required dependencies.

Open the application sources that are already on your machine

  • Click Open or Import on the Welcome screen or select File | Open from the main menu. In the dialog that opens, select the folder where your sources are stored.

Check out the application sources from your version control

  1. Click Clone Repository on the Welcome screen.

    Alternatively, select File | New | Project from Version Control or Git | Clone or VCS | Get from Version Control from the main menu.

    Instead of Git in the main menu, you may see any other Version Control System that is associated with your project. For example, Mercurial or Perforce.

  2. In the dialog that opens, select your version control system from the list and specify the repository to check out the application sources from. For more information, refer to Check out a project (clone).

Download the dependencies

  • Click Run 'npm install' or Run 'yarn install' in the popup:

    Open an application and download the dependencies

    You can use npm, Yarn 1, or Yarn 2, refer to npm and Yarn for details.

  • Alternatively, select Run 'npm install' or Run 'yarn install' from the context menu of package.json in the editor or in the Project tool window Alt+1.

Project security

When you open a project that was created outside IntelliJ IDEA and was imported into it, IntelliJ IDEA displays a dialog where you can decide how to handle this project with unfamiliar source code.

Select one of the following options:

  • Preview in Safe Mode: in this case, IntelliJ IDEA opens the project in a preview mode. It means that you can browse the project's sources but you cannot run tasks and script or run/debug your project.

    IntelliJ IDEA displays a notification on top of the editor area, and you can click the Trust project link and load your project at any time.

  • Trust Project: in this case, IntelliJ IDEA opens and loads a project. That means the project is initialized, project's plugins are resolved, dependencies are added, and all IntelliJ IDEA features are available.

  • Don't Open: in this case, IntelliJ IDEA doesn't open the project.

Learn more from Project security.

Run and debug Next.js applications

With IntelliJ IDEA, you can run your application and start debugging sessions in two ways:

  • From the editor - run the next dev command as a script from package.json or in the Terminal. Then start a debugging session by clicking the application URL in the Run tool window or in the Terminal.

  • Using run/debug configurations.

Start running and debugging from the editor

Run an application with next dev

  1. Сlick the Run icon in the gutter next to the dev script in package.json, or execute the next dev command in the Terminal Alt+F12, or double-click the dev task in the npm tool window (View | Tool Windows | npm).

    Run next dev from package.json
  2. Wait till the application is compiled and the development server is ready.

    The Run tool window or the Terminal shows the URL at which your application is running, the default URL is http://localhost:3000.

    Run tool window with a link to the app

    Click this link to view the application in the browser.

Start a debugging session from the Run tool window or from the Terminal

  1. Set breakpoints where necessary.

  2. Сlick the Run icon in the gutter next to the dev script in package.json, or execute the next dev command in the Terminal Alt+F12, or double-click the dev task in the npm tool window (View | Tool Windows | npm).

  3. Wait till the application is compiled and the development server is ready.

    The Run tool window or the Terminal shows the URL at which your application is running, the default URL is http://localhost:3000.

    Start a debugging session from the Run tool window

    Hold Ctrl+Shift and click the link.

  4. When the application opens in the browser, perform the actions that trigger the program execution, for example, click a link. The focus switches to IntelliJ IDEA with the Debug tool window open.

    Debugging session started

    Proceed as usual: step through the program, stop and resume program execution, examine it when suspended, explore the call stack and variables, set watches, evaluate variables, view actual HTML DOM, and so on.

Run and debug a Next.js application with run/debug configurations

When you open a single-repo project with the next package listed as dependency in the root package.json, IntelliJ IDEA automatically generates two run/debug configurations:

  • Next.js: server-side of the type npm. The configuration executes the next dev command that starts the development server and runs your application in the development mode.

  • Next.js: debug client-side of the type JavaScript Debug to debug your application in the browser.

Two run/debug configurations are generated

Create run/debug configurations

  1. Go to Run | Edit Configurations. Alternatively, select Edit Configurations from the Run widget on the toolbar.

    Open the Edit Configurations dialog

    In the Edit Configurations dialog that opens, click the Add button (the Add button) on the toolbar and select npm from the list.

  2. In the Configuration tab of the Run/Debug Configurations: npm dialog that opens, specify the location of the package.json, the Node.js interpreter, and the package manager to use.

    In the Command field, select run from the list and then select the script to run from the Scripts list. Most likely it will be the default dev script but you can configure another one in your package.json, for example, to run the application on a custom port.

    npm run/debug configuration
  3. Optionally:

    To open the application in the browser, update the configuration as follows: in the Browser / Live Edit tab, select the After launch checkbox, select the browser to open the application in, and specify the URL address at which the application wil run.

    Browser / Live Edit tab: select browser

Run an application in the development mode with the npm run/debug configuration

  1. From the list in the Run widget on the toolbar, select a run configuration of the type npm. This can be the autogenerated Next.js: server-side configuration or a custom one that you created yourself as described above.

    Run a Next.js app in the development mode via a run/debug configuration

    Click the Run icon.

  2. When the application is compiled and the development server is ready, the Run tool window shows the URL at which your application is running. The default URL is http://localhost:3000, however if the default port 3000 is already busy, the server tries starting on the closest free port.

    Running Next.js app in the development mode: the Development server is ready

    Click this link to view the application.

    Alternatively, enable IntelliJ IDEA to open the application on start as described above.

Start debugging with a JavaScript Debug configuration

  1. Set breakpoints where necessary.

  2. Run your application in the development mode with an npm run/debug configuration or with next dev.

  3. When the application is compiled and the development server is ready, the Run tool window shows the URL at which your application is running. The default URL is http://localhost:3000, however if the default port 3000 is already busy, the server tries starting on the closest free port.

  4. From the list in the Run widget on the toolbar, select a run configuration of the type JavaScript Debug. This can be the autogenerated Next.js: debug client configuration or a custom one that you created yourself as described above.

    Start a debugging session — select the JavaScript Debug run configuration

    Click the Debug icon.

  5. When the application opens in the browser, perform the actions that trigger the program execution, for example, click a link. The focus switches to IntelliJ IDEA with the Debug tool window open.

    Proceed as usual: step through the program, stop and resume program execution, examine it when suspended, explore the call stack and variables, set watches, evaluate variables, view actual HTML DOM, and so on.

Please, refer to Run a React application and Debug a React application.

Last modified: 11 April 2025