Connect a Vite browser application to Bugsink
When JavaScript fails in a user’s browser, Bugsink gives you the exception and the original application code behind the production bundle.
This guide adds error reporting to a Vite application, uploads its source map, and triggers a deliberate browser error. To follow along, create a Bugsink project and copy its DSN. The quickstart guide shows where to find it.
Install the browser SDK
Install the open-source Sentry SDK for browser JavaScript. Bugsink accepts the Sentry event protocol, so the SDK can send errors directly to your Bugsink project:
npm install @sentry/browsernpm install @sentry/browser
Initialize the SDK in your browser entry point
Import and initialize the SDK before the rest of your client-side code. Vite
exposes variables prefixed with VITE_ to browser code, so this example reads
the project DSN from VITE_SENTRY_DSN. A DSN identifies the project and is
safe to include in the browser bundle; it is not an administrative token.
The button handler is the application’s ordinary browser code. Its exception is deliberate for this setup check:
import * as Sentry from "@sentry/browser"; Sentry.init({ dsn: import.meta.env.VITE_SENTRY_DSN, }); document.querySelector("#checkout").addEventListener("click", () => { throw new Error("Browser checkout failed [vite-browser]"); });import * as Sentry from "@sentry/browser"; Sentry.init({ dsn: import.meta.env.VITE_SENTRY_DSN, }); document.querySelector("#checkout").addEventListener("click", () => { throw new Error("Browser checkout failed [vite-browser]"); });
Build with source maps
Production JavaScript is bundled and minified, so its generated line numbers do not point at the source you edit. Tell Vite to emit a source map with every production build:
import { defineConfig } from "vite"; export default defineConfig({ build: { sourcemap: true, }, });import { defineConfig } from "vite"; export default defineConfig({ build: { sourcemap: true, }, });
Supply the Bugsink DSN when Vite builds the browser bundle:
VITE_SENTRY_DSN=https://key@bugsink.example/1 npm run buildVITE_SENTRY_DSN=https://key@bugsink.example/1 npm run build
Upload the source maps to Bugsink
sentry-cli adds a matching debug ID to the bundle and source map, then
uploads both to Bugsink. Create a project-bound Bugsink token with the
debug-files:upload capability and keep it in your build environment rather
than in browser code.
Inject the debug IDs after the build:
npx --yes @sentry/cli sourcemaps inject ./distnpx --yes @sentry/cli sourcemaps inject ./dist
Then upload the result. Bugsink has no organization object, so --org is only
a compatibility value. Replace the URL and project slug with your own:
SENTRY_AUTH_TOKEN=your-project-token \ npx --yes @sentry/cli \ --url https://bugsink.example \ sourcemaps --org bugsink --project your-project-slug upload ./distSENTRY_AUTH_TOKEN=your-project-token \ npx --yes @sentry/cli \ --url https://bugsink.example \ sourcemaps --org bugsink --project your-project-slug upload ./dist
Upload source maps for every production build before it can report errors.
You may remove the .map files from dist after a successful upload if you do
not want the web server to publish them.
Trigger the test error
Serve the production build, open the page, and click Test a failed checkout:
npm run previewnpm run preview
The uncaught exception still follows normal browser behavior; the SDK reports it in the background.
See the original source in Bugsink
Open the new issue in Bugsink. The source map translates the production bundle back to the browser entry point and shows the exact line that threw the error.
Error
That’s it: your Vite browser application is connected. Remove the deliberate exception; uncaught errors from real browser sessions will now reach Bugsink with their original source context.
