Upload source maps for Vite

  1. Install the PostHog Rollup plugin

    Required

    Vite uses Rollup under the hood, so you can use the PostHog Rollup plugin to upload source maps:

    Terminal
    npm install @posthog/rollup-plugin
  2. Add PostHog plugin to your Vite config

    Required

    Add the PostHog plugin to your vite.config.js file:

    vite.config.js
    import { defineConfig } from 'vite'
    import posthog from '@posthog/rollup-plugin'
    export default defineConfig({
    plugins: [
    posthog({
    personalApiKey: process.env.POSTHOG_API_KEY, // Personal API Key
    envId: process.env.POSTHOG_ENV_ID, // Environment ID
    host: process.env.POSTHOG_HOST, // (optional) defaults to https://us.i.posthog.com
    sourcemaps: { // (optional)
    enabled: true, // (optional) Enable sourcemaps generation and upload, defaults to true
    project: 'my-application', // (optional) Project name
    version: '1.0.0', // (optional) Release version
    deleteAfterUpload: true, // (optional) Delete sourcemaps after upload, defaults to true
    },
    }),
    ],
    })

    Set the following environment variables:

    Environment variableDescription
    POSTHOG_API_KEYPersonal API key with at least write access on error tracking
    POSTHOG_ENV_IDProject ID you can find in your project settings
    POSTHOG_HOST(optional) Your PostHog instance URL. Defaults to https://us.i.posthog.com
    Using CI/CD?

    Add these environment variables to your CI/CD service's project settings to automatically upload source maps during production builds.

  3. Verify source map upload and injection

    Checkpoint

    Confirm source maps were successfully uploaded:

    1. Go to your symbol sets in PostHog and verify your latest upload appears.

    2. Check your production JavaScript files in browser dev tools. They should include a source map reference comment:

    JavaScript
    //# chunkId=0197e6db-9a73-7b91-9e80-4e1b7158db5c

Community questions

Was this page useful?

Questions about this page? or post a community question.