Skip to main content
The @nx/next plugin integrates Next.js into your Nx workspace. It provides generators for scaffolding full applications, pages, and components, along with dedicated executors for building and serving Next.js apps. TypeScript, Playwright, Cypress, and Jest support are included with no extra configuration.

Installation

Or install manually:
@nx/next requires next 14.x or 15.x/16.x as a peer dependency. Install it alongside this plugin: npm install next react react-dom.

What the plugin provides

Generators

Scaffold Next.js applications, pages, components, and libraries. Includes custom server setup.

Executors

Dedicated build and server executors purpose-built for Next.js production builds and development serving.

Inferred tasks

Automatically infers build, serve, and start targets from your Next.js config file.

Generators

application

Create a new Next.js application.
Choose your end-to-end testing setup:

page

Create a new page inside an existing Next.js application.

component

Generate a React component within a Next.js project.

library

Create a shared library that can be imported by your Next.js application and other workspace projects.

custom-server

Add a custom Express-based server to a Next.js application.

convert-to-inferred

Migrate an existing Next.js project from using the @nx/next:build executor to using the inferred task plugin (@nx/next/plugin).

Executors

build

Build a Next.js application for production. Runs next build under the hood.
Run the build:

server

Serve a Next.js application in development mode. Runs next dev under the hood with Nx’s watch integration.
Run the dev server:

Inferred tasks

When @nx/next/plugin is registered in nx.json, Nx automatically infers targets from your next.config.js or next.config.ts file. This means you do not need to configure targets in project.json manually.
With inferred tasks configured, these commands work automatically:

Configuration examples

next.config.ts with Nx paths

Full project.json example

Importing workspace libraries

Next.js applications in an Nx workspace can import shared libraries using TypeScript path aliases. Nx configures these automatically via tsconfig.base.json.
Run nx graph to visualize the dependency graph between your Next.js applications and shared libraries.