@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
@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.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. Runsnext build under the hood.
server
Serve a Next.js application in development mode. Runsnext dev under the hood with Nx’s watch integration.
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.
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 viatsconfig.base.json.
