vite-plugin-sentry
raw JSON → 1.4.1 verified Mon Apr 27 auth: no javascript
Unofficial Sentry plugin for Vite that creates releases and uploads sourcemaps during the Vite build process, using @sentry/cli. Version 1.4.1 supports Vite 2.6–6.x and Node >=14. Built on TypeScript with full type definitions. Unlike the official webpack plugin, it offers virtual module integration to share release/dist config with the Sentry client, and optional automatic commit tracking and deployment environment configuration. Known for breaking changes in error handling (1.2.0) and deprecation of virtual module paths (1.1.5).
Common errors
error Error: Could not read auth token. Run 'sentry-cli login' or set the SENTRY_AUTH_TOKEN environment variable. ↓
cause Missing or invalid authToken in config or environment.
fix
Set authToken in plugin options or export SENTRY_AUTH_TOKEN environment variable.
error [vite-plugin-sentry] Sourcemaps upload failed: HTTP 403 Forbidden ↓
cause Sentry auth token lacks permissions (project:write or org:integrations).
fix
Generate a new auth token in Sentry with 'project:write' and 'org:integrations' scopes.
error Uncaught TypeError: Cannot read properties of undefined (reading 'dist') ↓
cause Virtual module 'virtual:vite-plugin-sentry/sentry-config' not imported before accessing import.meta.env.VITE_PLUGIN_SENTRY_CONFIG.
fix
Ensure import 'virtual:vite-plugin-sentry/sentry-config' is at the top of your entry file.
error Cannot find module 'vite-plugin-sentry' or its corresponding type declarations. ↓
cause Missing or mismatched package installation; or TypeScript cannot resolve types.
fix
Install vite-plugin-sentry as a dev dependency: npm install -D vite-plugin-sentry. Ensure tsconfig.json includes node_modules in typeRoots.
Warnings
breaking Since v1.2.0, Sentry upload errors crash the build instead of printing warnings. Use legacyErrorHandlingMode: true to revert. ↓
fix Add legacyErrorHandlingMode: true to plugin options.
deprecated Virtual module path 'virtual:vite-plugin-sentry/sentry-release' is deprecated since v1.1.5 and may be removed. Use 'virtual:vite-plugin-sentry/sentry-config' instead. ↓
fix Replace 'sentry-release' with 'sentry-config' in imports.
gotcha Plugin requires build.sourcemap: true in Vite config to generate sourcemaps for upload. Missing this will cause no sourcemaps to be uploaded. ↓
fix Add sourcemap: true to Vite build options.
gotcha In TypeScript, you must add 'vite-plugin-sentry/client' to tsconfig types or use a reference directive to get types for the virtual module and import.meta.env. ↓
fix Add "types": ["vite-plugin-sentry/client"] in tsconfig.json.
gotcha From v1.1.6, the package uses .mjs for module entry and supports both ESM and CJS via conditional exports. CommonJS require() may not work in older Node versions (<14). ↓
fix Use import or upgrade Node to >=14.
Install
npm install vite-plugin-sentry yarn add vite-plugin-sentry pnpm add vite-plugin-sentry Imports
- viteSentry wrong
const viteSentry = require('vite-plugin-sentry')correctimport viteSentry from 'vite-plugin-sentry' - ViteSentryPluginOptions wrong
import { ViteSentryPluginOptions } from 'vite-plugin-sentry'correctimport type { ViteSentryPluginOptions } from 'vite-plugin-sentry' - virtual:vite-plugin-sentry/sentry-config wrong
import config from 'virtual:vite-plugin-sentry/sentry-release'correctimport 'virtual:vite-plugin-sentry/sentry-config'
Quickstart
import { defineConfig } from 'vite';
import viteSentry from 'vite-plugin-sentry';
export default defineConfig({
plugins: [
viteSentry({
url: 'https://sentry.io',
authToken: process.env.SENTRY_AUTH_TOKEN ?? '',
org: 'my_org',
project: 'my_project',
release: '1.0',
deploy: { env: 'production' },
setCommits: { auto: true },
sourceMaps: {
include: ['./dist/assets'],
ignore: ['node_modules'],
urlPrefix: '~/assets'
}
})
],
build: { sourcemap: true }
});