Upload source maps for Vite

AI wizard

Set up source map uploading automatically with our wizard by running this command in your project directory with your terminal (it also works for LLM coding agents like Cursor and Bolt):

Learn more

Manual setup

  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
    projectId: process.env.POSTHOG_PROJECT_ID, // Project 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
    releaseName: 'my-application', // (optional) Release name
    releaseVersion: '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_PROJECT_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.