---
title: next.config.js Options
description: Learn how to configure your application with next.config.js.
url: "https://nextjs.org/docs/14/app/api-reference/next-config-js"
version: 14.2.35
lastUpdated: 2024-02-23
prerequisites:
  - "API Reference: /docs/14/app/api-reference"
---


Next.js can be configured through a `next.config.js` file in the root of your project directory (for example, by `package.json`).

```js filename="next.config.js"
/** @type {import('next').NextConfig} */
const nextConfig = {
  /* config options here */
}

module.exports = nextConfig
```

`next.config.js` is a regular Node.js module, not a JSON file. It gets used by the Next.js server and build phases, and it's not included in the browser build.

If you need [ECMAScript modules](https://nodejs.org/api/esm.html), you can use `next.config.mjs`:

```js filename="next.config.mjs"
/**
 * @type {import('next').NextConfig}
 */
const nextConfig = {
  /* config options here */
}

export default nextConfig
```

You can also use a function:

```js filename="next.config.mjs"
export default (phase, { defaultConfig }) => {
  /**
   * @type {import('next').NextConfig}
   */
  const nextConfig = {
    /* config options here */
  }
  return nextConfig
}
```

Since Next.js 12.1.0, you can use an async function:

```js filename="next.config.js"
module.exports = async (phase, { defaultConfig }) => {
  /**
   * @type {import('next').NextConfig}
   */
  const nextConfig = {
    /* config options here */
  }
  return nextConfig
}
```

`phase` is the current context in which the configuration is loaded. You can see the [available phases](https://github.com/vercel/next.js/blob/5e6b008b561caf2710ab7be63320a3d549474a5b/packages/next/shared/lib/constants.ts#L19-L23). Phases can be imported from `next/constants`:

```js
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants')

module.exports = (phase, { defaultConfig }) => {
  if (phase === PHASE_DEVELOPMENT_SERVER) {
    return {
      /* development only config options here */
    }
  }

  return {
    /* config options for all phases except development here */
  }
}
```

The commented lines are the place where you can put the configs allowed by `next.config.js`, which are [defined in this file](https://github.com/vercel/next.js/blob/canary/packages/next/src/server/config-shared.ts).

However, none of the configs are required, and it's not necessary to understand what each config does. Instead, search for the features you need to enable or modify in this section and they will show you what to do.

> Avoid using new JavaScript features not available in your target Node.js version. `next.config.js` will not be parsed by Webpack, Babel or TypeScript.

This page documents all the available configuration options:

- [appDir](/docs/14/app/api-reference/next-config-js/appDir)
  - Enable the App Router to use layouts, streaming, and more.
- [assetPrefix](/docs/14/app/api-reference/next-config-js/assetPrefix)
  - Learn how to use the assetPrefix config option to configure your CDN.
- [basePath](/docs/14/app/api-reference/next-config-js/basePath)
  - Use `basePath` to deploy a Next.js application under a sub-path of a domain.
- [compress](/docs/14/app/api-reference/next-config-js/compress)
  - Next.js provides gzip compression to compress rendered content and static files, it only works with the server target. Learn more about it here.
- [devIndicators](/docs/14/app/api-reference/next-config-js/devIndicators)
  - Optimized pages include an indicator to let you know if it's being statically optimized. You can opt-out of it here.
- [distDir](/docs/14/app/api-reference/next-config-js/distDir)
  - Set a custom build directory to use instead of the default .next directory.
- [env](/docs/14/app/api-reference/next-config-js/env)
  - Learn to add and access environment variables in your Next.js application at build time.
- [eslint](/docs/14/app/api-reference/next-config-js/eslint)
  - Next.js reports ESLint errors and warnings during builds by default. Learn how to opt-out of this behavior here.
- [exportPathMap](/docs/14/app/api-reference/next-config-js/exportPathMap)
  - Customize the pages that will be exported as HTML files when using `next export`.
- [generateBuildId](/docs/14/app/api-reference/next-config-js/generateBuildId)
  - Configure the build id, which is used to identify the current build in which your application is being served.
- [generateEtags](/docs/14/app/api-reference/next-config-js/generateEtags)
  - Next.js will generate etags for every page by default. Learn more about how to disable etag generation here.
- [headers](/docs/14/app/api-reference/next-config-js/headers)
  - Add custom HTTP headers to your Next.js app.
- [httpAgentOptions](/docs/14/app/api-reference/next-config-js/httpAgentOptions)
  - Next.js will automatically use HTTP Keep-Alive by default. Learn more about how to disable HTTP Keep-Alive here.
- [images](/docs/14/app/api-reference/next-config-js/images)
  - Custom configuration for the next/image loader
- [cacheHandler](/docs/14/app/api-reference/next-config-js/incrementalCacheHandlerPath)
  - Configure the Next.js cache used for storing and revalidating data to use any external service like Redis, Memcached, or others.
- [logging](/docs/14/app/api-reference/next-config-js/logging)
  - Configure how data fetches are logged to the console when running Next.js in development mode.
- [mdxRs](/docs/14/app/api-reference/next-config-js/mdxRs)
  - Use the new Rust compiler to compile MDX files in the App Router.
- [onDemandEntries](/docs/14/app/api-reference/next-config-js/onDemandEntries)
  - Configure how Next.js will dispose and keep in memory pages created in development.
- [optimizePackageImports](/docs/14/app/api-reference/next-config-js/optimizePackageImports)
  - API Reference for optmizedPackageImports Next.js Config Option
- [output](/docs/14/app/api-reference/next-config-js/output)
  - Next.js automatically traces which files are needed by each page to allow for easy deployment of your application. Learn how it works here.
- [pageExtensions](/docs/14/app/api-reference/next-config-js/pageExtensions)
  - Extend the default page extensions used by Next.js when resolving pages in the Pages Router.
- [Partial Prerendering (experimental)](/docs/14/app/api-reference/next-config-js/partial-prerendering)
  - Learn how to enable Partial Prerendering (experimental) in Next.js 14.
- [poweredByHeader](/docs/14/app/api-reference/next-config-js/poweredByHeader)
  - Next.js will add the `x-powered-by` header by default. Learn to opt-out of it here.
- [productionBrowserSourceMaps](/docs/14/app/api-reference/next-config-js/productionBrowserSourceMaps)
  - Enables browser source map generation during the production build.
- [reactStrictMode](/docs/14/app/api-reference/next-config-js/reactStrictMode)
  - The complete Next.js runtime is now Strict Mode-compliant, learn how to opt-in
- [redirects](/docs/14/app/api-reference/next-config-js/redirects)
  - Add redirects to your Next.js app.
- [rewrites](/docs/14/app/api-reference/next-config-js/rewrites)
  - Add rewrites to your Next.js app.
- [serverActions](/docs/14/app/api-reference/next-config-js/serverActions)
  - Configure Server Actions behavior in your Next.js application.
- [serverComponentsExternalPackages](/docs/14/app/api-reference/next-config-js/serverComponentsExternalPackages)
  - Opt-out specific dependencies from the Server Components bundling and use native Node.js `require`.
- [trailingSlash](/docs/14/app/api-reference/next-config-js/trailingSlash)
  - Configure Next.js pages to resolve with or without a trailing slash.
- [transpilePackages](/docs/14/app/api-reference/next-config-js/transpilePackages)
  - Automatically transpile and bundle dependencies from local packages (like monorepos) or from external dependencies (`node_modules`).
- [turbo](/docs/14/app/api-reference/next-config-js/turbo)
  - Configure Next.js with Turbopack-specific options
- [typedRoutes](/docs/14/app/api-reference/next-config-js/typedRoutes)
  - Enable experimental support for statically typed links.
- [typescript](/docs/14/app/api-reference/next-config-js/typescript)
  - Next.js reports TypeScript errors by default. Learn to opt-out of this behavior here.
- [urlImports](/docs/14/app/api-reference/next-config-js/urlImports)
  - Configure Next.js to allow importing modules from external URLs (experimental).
- [webpack](/docs/14/app/api-reference/next-config-js/webpack)
  - Learn how to customize the webpack config used by Next.js
- [webVitalsAttribution](/docs/14/app/api-reference/next-config-js/webVitalsAttribution)
  - Learn how to use the webVitalsAttribution option to pinpoint the source of Web Vitals issues.

---

For an index of all available documentation, see [/docs/14/llms.txt](/docs/14/llms.txt)