Automated CLI wizard to add Rollbar to an existing Next.js application.
It detects your project structure, scaffolds the right config, and wires up error handling, Session Replay, and source maps for you.
Note: Today this wizard only supports Next.js projects. Vue and Svelte support are planned for future releases.
-
Next.js-aware project detection:
- Detects App Router (
app/), Pages Router (pages/), or both. - Detects TypeScript vs JavaScript.
- Detects your package manager (
npm,yarn,pnpm).
- Detects App Router (
-
Vercel + Rollbar Integration aware:
- Asks if you are deploying with Vercel.
- If you have installed the Rollbar integration in Vercel, you can paste the names of the environment variables it created.
- Uses those Vercel-managed env vars throughout the generated config without writing tokens into
.env.local.
-
Rollbar setup for client + server:
- Creates
rollbar.server.config.(ts|js)for server-side and edge handlers. - Creates
rollbar.edge.config.(ts|js)for edge runtimes. - Creates
rollbar.client.config.(ts|js)for browser-side error tracking and Session Replay.
- Creates
-
Next.js integration:
- Configures or creates
next.config.(js|mjs|ts)when source maps are enabled. - Sets up an
instrumentation.(ts|js)hook when needed. - Adds App Router
global-error.(tsx|jsx)and/or Pages Router_error.(tsx|jsx)if not present.
- Configures or creates
-
Source maps & deployment tracking:
- Generates a
scripts/upload-sourcemaps.(ts|js)helper. - Installs required packages (e.g.
form-data,node-fetch,glob, plustsxand types when needed). - Adds a
postbuildscript to run the upload script. - Optionally configures Rollbar code versioning for deployment tracking.
- Generates a
-
Environment configuration:
- Updates
.env.localwith Rollbar tokens (non-Vercel) or helpful comments (Vercel). - Ensures
.env.localis in.gitignore.
- Updates
-
Optional example page & API route:
- Can generate a
rollbar-example-pageand example API route to validate your setup.
- Can generate a
- Node.js:
>=16.0.0 - Framework: Next.js (App Router, Pages Router, or both)
- Project: Run the wizard from the root of your Next.js app (where
package.jsonlives) - Rollbar: Server and client project access tokens (unless using Vercel’s Rollbar integration)
You can use the wizard via npx, or install it as a dev dependency, or globally.
- Using
npx(recommended to start):
cd my-nextjs-app
npx @rollbar/wizard- As a dev dependency:
npm install --save-dev @rollbar/wizard
# or
yarn add -D @rollbar/wizard
# or
pnpm add -D @rollbar/wizardThen:
cd my-nextjs-app
npx rollbar-wizard
# or, depending on your package manager
pnpm exec rollbar-wizard
yarn rollbar-wizard- Globally (optional):
npm install -g @rollbar/wizard
rollbar-wizardFrom your Next.js project root:
# Let the wizard auto-detect that this is a Next.js app
rollbar-wizard
# Or explicitly specify the framework
rollbar-wizard nextjsThe wizard will:
- Inspect your project to detect:
- App Router / Pages Router / both
- TypeScript / JavaScript
- Package manager
- Ask how you deploy (e.g. Vercel vs non-Vercel).
- Ask for:
- Rollbar server access token
- Rollbar client access token
- Environment name (e.g.
production,staging) - Whether to enable deployment tracking
- Whether to enable source maps
- Whether to enable Session Replay
- Whether to create an example page.
- Apply changes and print a summary of what it configured.
Depending on your answers and project structure, the wizard may:
-
Config files:
- Create or overwrite:
rollbar.server.config.(ts|js)rollbar.edge.config.(ts|js)rollbar.client.config.(ts|js)
- Create or overwrite:
-
Next.js config:
- Create or update:
next.config.js,next.config.mjs, ornext.config.ts
- Ensures
productionBrowserSourceMaps: truewhen source maps are enabled. - Uses a minimal config when it detects an “empty” config file.
- Create or update:
-
Instrumentation:
- Create
instrumentation.(ts|js)at the project root or undersrc/, or - Print a snippet you can paste into your existing instrumentation file, and ask you to confirm before continuing.
- Create
-
Error pages:
- For Pages Router:
- Create
_error.(tsx|jsx)underpages/orsrc/pages/if one does not exist.
- Create
- For App Router:
- Create
global-error.(tsx|jsx)under yourapp/tree if one does not exist.
- Create
- For Pages Router:
-
Example page & API route (optional):
- App Router:
app/rollbar-example-page/page.(tsx|jsx)app/api/rollbar-example-api/route.(ts|js)
- Pages Router:
pages/rollbar-example-page.(tsx|jsx)(or undersrc/pages/)pages/api/rollbar-example-api.(ts|js)
- App Router:
-
Environment variables:
- Update
.env.local:- For non-Vercel:
ROLLBAR_PROJECT_ACCESS_SERVER_TOKEN=...NEXT_PUBLIC_ROLLBAR_PROJECT_ACCESS_CLIENT_TOKEN=...- Optional
ROLLBAR_CODE_VERSION=...
- For Vercel:
- Adds comments documenting which Vercel env vars you configured.
- For non-Vercel:
- Ensure
.env.localis ignored by Git by updating.gitignore.
- Update
-
Source maps:
- Create
scripts/upload-sourcemaps.(ts|js)with a ready-to-run upload script. - Install and/or add to
devDependencies:form-data,node-fetch,globtsxand@types/globfor TypeScript projects.
- Add or extend your
postbuildscript to run the upload script. - Update
tsconfig.jsonto excludescripts/from type checking.
- Create
If you indicate that you are deploying with Vercel:
- The wizard will first confirm that you are using Vercel.
- In your Vercel project, after installing the Rollbar integration, Vercel creates environment variables for your Rollbar client and server tokens.
- The wizard asks you to paste the names of those environment variables (for example
VERCEL_ROLLBAR_CLIENT_TOKENandVERCEL_ROLLBAR_SERVER_TOKEN). - It then configures all generated Rollbar code (server, edge, and client config, plus source map upload) to read from those Vercel env vars.
- It avoids writing tokens into
.env.local; instead, it only adds comments that reference the Vercel env vars for clarity. - Deployment tracking is treated as handled by Vercel; the wizard skips its own deployment-tracking prompt in that mode.
After running the wizard:
-
Install dependencies (if you used
--skip-install):npm install # or yarn install # or pnpm install
-
Start your app:
npm run dev
-
If you created the example page:
- Visit
/rollbar-example-pagein your browser. - Trigger client- and server-side errors to see them appear in Rollbar.
- Visit
-
Verify source maps (if enabled):
- Build and deploy your app, then trigger an error in production.
- Check that stack traces in Rollbar are symbolicated to your original source.
-
Framework support:
- Only Next.js is supported today.
- The wizard expects a
package.jsonwithnextindependenciesordevDependencies.
-
Project shape:
- Assumes a relatively standard Next.js layout:
app/and/orpages/under the project root orsrc/.
- Non-standard layouts may require manual adjustments after running the wizard.
- Assumes a relatively standard Next.js layout:
-
Token management:
- For non-Vercel setups, tokens are written into
.env.localon your machine. - You are responsible for configuring secrets in CI and production environments.
- For non-Vercel setups, tokens are written into
Planned improvements (subject to change):
- Vue support:
- CLI mode (e.g.
rollbar-wizard vue) with framework-specific templates.
- CLI mode (e.g.
- Svelte/SvelteKit support:
- CLI mode (e.g.
rollbar-wizard svelte) with appropriate routing and error-handling integration.
- CLI mode (e.g.
- Additional platform presets:
- More guided flows for other hosting providers beyond Vercel.
If you have specific requirements for Vue or Svelte, opening an issue with your use case will help shape the initial implementation.
Issues and pull requests are welcome.
- Bugs / Feature requests: open an issue on the GitHub repository.
- Local development:
- Build with
npm run build - Run tests with
npm test - Use
npm run devfor TypeScript watch mode while testing the CLI in a sample Next.js app.
- Build with
MIT License.