JavaScript · TypeScript

Fix JavaScript and TypeScript production errors automatically

When your Express or Next.js server throws an uncaught error, Bugstack works out the cause and sends the fix as a pull request: a TypeError, a null access, a failed await, a broken import. The SDK is the crash-capture part of a product that maintains your whole repository.

What JS/TS Errors Bugstack Fixes

  • TypeError — null/undefined property access (Cannot read properties of undefined)
  • x.map is not a function — calling array methods on non-array values
  • Missing or wrong local imports — a require or import that fails at runtime
  • Unhandled async failures — missing await, unhandled promise rejection
  • Next.js route handler errors — exceptions in App Router route handlers wrapped with withErrorCapture

Install the SDK

Install the SDK:

npm install bugstack-sdk

Then add it to your Express app, with your API key and the Bugstack endpoint:

const { initBugStack, bugstackErrorHandler } = require('bugstack-sdk/express')

// After app creation:
app.use(initBugStack({
  apiKey: process.env.BUGSTACK_API_KEY,
  endpoint: process.env.BUGSTACK_ENDPOINT || 'https://dashboard.bugstack.ai/api/ingest/sdk',
}))

// ... your routes ...

// Before app.listen:
app.use(bugstackErrorHandler())

Using Next.js? Wrap your route handlers with withErrorCapture: see the installation guide. Only the route handlers you wrap are reported; errors in server components, server actions, middleware and the browser are not captured.

Example Fix

Bugstack detects a TypeError caused by accessing a property on null and writes a small fix:

Before (broken)

export function getUserName(user) {
  return user.profile.name;
}

// Runtime error when user.profile is null:
// TypeError: Cannot read properties
//   of null (reading 'name')

After (fixed by Bugstack)

export function getUserName(user) {
  if (!user?.profile) {
    return null;
  }
  return user.profile.name;
}

Proven before you see it

Bugstack does not send this fix on trust. In an isolated copy of your repository, with the network cut, it writes a test that reproduces the crash and runs it with Vitest, Jest or Mocha on your current code: it fails with the same TypeError. With the fix the test passes, and the rest of your suite still passes. Only then does the pull request open, with the test and that proof in it.

The reproduction test, shipped in the pull request

import { test, expect } from 'vitest'
import { getUserName } from './users'

test('getUserName returns null without a profile', () => {
  // Before the fix: TypeError: Cannot read properties
  //   of null (reading 'name')
  expect(getUserName({ profile: null })).toBeNull()
})

See how the verification sandbox works.

What else Bugstack does for this repository

The SDK is one part. Once your repository is connected, Bugstack also scans your npm packages for known vulnerabilities and outdated versions, scans for secrets, and acts on failed deploys if you host on Render. It scans and reports, and it can open pull requests for what it finds. Those pull requests are switched on per account. Every change arrives as a pull request, and you set how much happens without you.

Full installation guide with config reference →

See it work on your own code.

$100 a month

Includes $100 of usage credit every month. Start with a 14-day trial: $50 of credit and a first security audit on us. A card is required.