---
title: How to configure Next.js plugins
description: A guide for configuring Next.js plugins with Nx
sidebar:
  label: 'How to configure Next.js plugins'
filter: 'type:Guides'
topics:
  - 'React'
  - 'Next.js'
---

Next.js applications generated by Nx use a plain `next.config.js` file. You configure Next.js options and compose other Next.js plugins directly, the same way you would outside a monorepo.

```js frame="none"
// next.config.js
//@ts-check

/** @type {import('next').NextConfig} */
const nextConfig = {
  // Next.js options go here
  // See: https://nextjs.org/docs/app/api-reference/config/next-config-js
};

module.exports = nextConfig;
```

{% aside type="caution" title="withNx and composePlugins were removed" %}
Nx v24 removed the `withNx` and `composePlugins` helpers from `@nx/next`. Their exports remain as inert stubs so an unmigrated `next.config.js` still loads, but they no longer configure anything. Follow the steps below to move to a plain `next.config.js`.
{% /aside %}

## Workspace libraries

The main job `withNx` did was make sure imported [workspace libraries](/docs/technologies/react/next/generators#library) were transpiled by Next.js. You no longer need `withNx` for this. Next.js transpiles workspace library source automatically on both Turbopack and webpack, so a plain `next.config.js` works with no extra configuration.

If you hit an "untranspiled dependency" error from a package, add it to Next's [`transpilePackages`](https://nextjs.org/docs/app/api-reference/config/next-config-js/transpilePackages) option:

```js frame="none"
// next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
  transpilePackages: ['@myorg/ui'],
};

module.exports = nextConfig;
```

## Composing other plugins

Compose Next.js plugins by calling them directly in `next.config.js`. For example, with [`@next/mdx`](https://www.npmjs.com/package/@next/mdx):

```js frame="none"
// next.config.js
const withMDX = require('@next/mdx')();

/** @type {import('next').NextConfig} */
const nextConfig = {
  // Next.js options go here
};

module.exports = withMDX(nextConfig);
```

Each plugin wraps the next, so you can nest as many as you need: `withA(withB(nextConfig))`.

## Migrating off withNx

Replace the wrapped config with a plain object and remove the `@nx/next` import.

Before:

```js frame="none"
// next.config.js
const { composePlugins, withNx } = require('@nx/next');

const nextConfig = {
  nx: {},
};

module.exports = composePlugins(withNx)(nextConfig);
```

After:

```js frame="none"
// next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
  // Next.js options go here
};

module.exports = nextConfig;
```

If your application set options under `nx: {}` in `withNx`, configure them yourself after migrating:

- **`nx.babelUpwardRootMode`.** Set babel `rootMode: 'upward'` in your own babel config if you need per-library `.babelrc` files to be picked up. See the [babel rootMode docs](https://babeljs.io/docs/options#rootmode).
- **`nx.fileReplacements` and `nx.assets`.** Configure these through your build setup directly.
- **SVGR.** Configure SVGR in `next.config.js` without Nx. See the [SVGR Next.js guide](https://react-svgr.com/docs/next/).
