> ## Documentation Index
> Fetch the complete documentation index at: https://docs.useflytrap.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Use Flytrap with Next.js

> Use Flytrap to catch & replay both front-end & back-end bugs in Next.js

## Installing

Install the `useflytrap` package to your Next.js project.

<CodeGroup>
  ```bash npm theme={null}
  npm install useflytrap
  ```

  ```bash yarn theme={null}
  yarn add useflytrap
  ```

  ```bash pnpm theme={null}
  pnpm install useflytrap
  ```
</CodeGroup>

## Add Flytrap code transform

Add the Flytrap code transform to your Next.js configuration, so that all your code gets properly processed for replaying.

<CodeGroup>
  ```typescript next.config.mjs theme={null}
  const { FlytrapTransformPlugin } = require('useflytrap/transform')

  /** @type {import("next").NextConfig} */
  const config = {
    reactStrictMode: true,

    webpack(config) {
      config.plugins = config.plugins ?? []
      // only add in production
      if (process.env.NODE_ENV === 'production') {
        config.plugins.push(FlytrapTransformPlugin.webpack())
      }
      return config
    },
  }
  module.exports = config
  ```
</CodeGroup>

<Snippet file="create-config.mdx" />

<Info>In Next.js, your Flytrap config might get cached, so you need to delete the `.next` folder after changing the Flytrap config for the changes to be applied.</Info>

#### Add Next.js specific `packageIgnores`

Next.js's internal code transform expects things such as font imports to be in the top level, without any kind of modifications. Due to this, we ignore the `next/font` package in our Flytrap configuration file:

<CodeGroup>
  ```typescript flytrap.config.ts theme={null}
  import { defineFlytrapConfig } from 'useflytrap'

  export default defineFlytrapConfig({
    // ... the rest of your config
    packageIgnores: ['next/font'] // 👈 ignores transformation of next/font package
  })
  ```
</CodeGroup>

## Catch your first bug

Now your app will be enabled with Flytrap. You can test out the setup by throwing an error in your development environment.

<img height="200" src="https://mintcdn.com/flytrap-98/_ZYKplWiYxS4sMge/images/dashboard/capture.png?fit=max&auto=format&n=_ZYKplWiYxS4sMge&q=85&s=ce61d7b322d5d0cb849a4c651416a277" className="rounded-lg" className="rounded-lg" data-path="images/dashboard/capture.png" />

## Example

<Card
  title="Next.JS usage example"
  icon={
<svg aria-label="Next.js logomark" class="next-mark_root__wLeec w-6 h-6" data-theme="light" height="40" role="img" viewBox="0 0 180 180" width="40"><mask height="180" id="mask0_408_134" maskUnits="userSpaceOnUse" style={{ maskType: 'alpha' }} width="180" x="0" y="0"><circle cx="90" cy="90" fill="black" r="90"></circle></mask><g mask="url(#mask0_408_134)"><circle cx="90" cy="90" data-circle="true" fill="black" r="90"></circle><path d="M149.508 157.52L69.142 54H54V125.97H66.1136V69.3836L139.999 164.845C143.333 162.614 146.509 160.165 149.508 157.52Z" fill="url(#paint0_linear_408_134)"></path><rect fill="url(#paint1_linear_408_134)" height="72" width="12" x="115" y="54"></rect></g><defs><linearGradient gradientUnits="userSpaceOnUse" id="paint0_linear_408_134" x1="109" x2="144.5" y1="116.5" y2="160.5"><stop stop-color="white"></stop><stop offset="1" stop-color="white" stop-opacity="0"></stop></linearGradient><linearGradient gradientUnits="userSpaceOnUse" id="paint1_linear_408_134" x1="121" x2="120.799" y1="54" y2="106.875"><stop stop-color="white"></stop><stop offset="1" stop-color="white" stop-opacity="0"></stop></linearGradient></defs></svg>
}
  href="https://github.com/useflytrap/flytrap-js/tree/main/examples/with-nextjs-api"
>
  See how you can use Flytrap with NextJS
</Card>

<Snippet file="learn-more.mdx" />
