Skip to main content

Introduction

Production Next.js builds are minified, so a stack trace from a real user looks like this:
When you upload your build’s source maps to Lerix, the dashboard maps each frame back to your original code, for example app/chat/page.tsx:142, and shows the surrounding lines. The maps are uploaded privately and deleted from your build output before you deploy. They are never served publicly, so your source code stays private.
Complete the Next.js installation first. Setting a release requires @lerix-dev/lerix-core 1.1.0 or newer.

1. Enable browser source maps

Turn on production browser source maps in your Next.js config:
next.config.ts
Run next build and check that .js.map files appear under .next/static/chunks.
Next.js adds a //# sourceMappingURL comment to the shipped JavaScript. That is harmless: the CLI deletes the maps before you deploy, so the comment just points to a file that returns 404.

2. Create a private API key

Uploading source maps needs a private key, separate from the public project key your app uses.
  1. Open your project in the Lerix Dashboard.
  2. Go to Project settings → API keys.
  3. Create a key with the Upload source maps permission (or Full access).
This key is secret. Store it as a CI secret and never put it in client code, a NEXT_PUBLIC_ variable, or your repository.

3. Upload the maps after each build

After next build and before you deploy, run the Lerix CLI on the .next folder:
Run it from your project folder. It finds the build output on its own (.next) and uses the version from package.json as the release. To set them yourself: npx @lerix-dev/lerix-cli upload .next --release 1.4.0. The CLI finds the maps under .next/static/chunks, uploads every *.js.map file (it skips node_modules and CSS maps), then deletes the .map files from the build output so they are never deployed. If any upload fails, it keeps the maps and exits with code 1, so you can retry the step. The CLI requires Node.js 18.17 or newer. If your hosting provider runs the build for you, run the upload in the same build command so it happens before the output is deployed, for example next build && npx @lerix-dev/lerix-cli upload.

Upload on every build

Instead of running the command yourself, install the CLI in your project and let npm run it after each build:
package.json
Now every npm run build uploads the maps. --optional keeps local builds working: on a machine without LERIX_SECRET_KEY (a developer’s laptop), the upload is skipped instead of failing the build, and the .map files are still deleted. Set the keys in your CI or build server, where the release build runs.
pnpm and Yarn 2+ don’t run postbuild scripts. Chain the command instead: "build": "next build && lerix upload --optional".

Options

Each option can also be set with an environment variable.

4. Pass the same release to the SDK

Set NEXT_PUBLIC_LERIX_RELEASE to the value you passed to --release. LerixNextProvider reads it automatically:
.env.local
Or pass release in options explicitly:
Lerix matches maps by the script’s file name. Next.js chunk names are content-hashed, so they are unique per build, and Lerix prefers maps from the same release. Matching still works if you omit release, but setting it is recommended. The release also replaces the 0.0.0 app version previously shown for web apps.
Use the same value in both places without editing it by hand: your git commit SHA or the version from package.json both work well.

Example: GitHub Actions

This workflow builds the app, uploads the maps, then deploys. Add LERIX_API_KEY, LERIX_PROJECT_ID and LERIX_SECRET_KEY as repository secrets.
.github/workflows/deploy.yml

What you see in the dashboard

New errors show the original file, line and function, with the surrounding code. Click Show minified to see the stack exactly as the browser sent it. The AI assistant, GitHub issues and the MCP server all receive the readable stack too.
  • Only errors reported after the maps are uploaded are mapped. Earlier errors keep their minified stack.
  • Lerix keeps the newest 5,000 maps per project.
  • Each map can be up to 50 MB.

Troubleshooting