Vite Plugin Tsconfig
raw JSON → 2.0.0 verified Mon Apr 27 auth: no javascript
Vite plugin to specify an alternate tsconfig filename, useful for monorepos and CI environments. Current stable version is 2.0.0, released with breaking changes migrating to buildStart/buildEnd hooks. Key differentiator: allows swapping tsconfig files per workspace package in monorepos, with backup/restore of the original tsconfig.json. Note that as of Vite 7.1.5, the native optimizeDeps.esbuildOptions.tsconfig option may suffice, but this plugin remains necessary for monorepos with externalized paths.
Common errors
error Error: Cannot find module 'vite-plugin-tsconfig' ↓
cause Package not installed or incorrect import path.
fix
Install the package: npm install -D vite-plugin-tsconfig
error TypeError: (0 , vite_plugin_tsconfig_1.default) is not a function ↓
cause Using CommonJS require() instead of ESM import.
fix
Use ES module import: import tsconfig from 'vite-plugin-tsconfig'
error Error: The plugin 'vite-plugin-tsconfig' requires Vite >= 3.1.6 ↓
cause Installed Vite version is too old.
fix
Update Vite: npm install vite@latest
error Error: ENOENT: no such file or directory, open 'tsconfig.build.json' ↓
cause The specified alternate tsconfig file does not exist.
fix
Ensure the file exists or create it. Check the filename option.
error Error: Failed to resolve import path in workspace package due to tsconfig not being swapped ↓
cause Workspace package not listed in workspaces option.
fix
Add the workspace package name to the workspaces array.
Warnings
breaking v2.0.0 migrated from configResolved/buildStart hooks to buildStart/buildEnd hooks, which may affect plugin ordering and lifecycle timing. ↓
fix Update plugin configuration if relying on specific hook behavior; in most cases no code changes are needed.
deprecated Plugin may be unnecessary for typical use cases as of Vite 7.1.5, which supports optimizeDeps.esbuildOptions.tsconfig natively. ↓
fix Consider removing the plugin and using Vite's native esbuildOptions.tsconfig.
gotcha The plugin swaps tsconfig.json files in-place; if the process is interrupted, the original tsconfig.json may not be restored. ↓
fix Ensure proper error handling or have version control to recover the original tsconfig.json.
gotcha The workspaces option only affects listed packages; it does not automatically read the root's workspaces from package.json. ↓
fix Explicitly list all workspace packages that need the alternate tsconfig.
gotcha Plugin hooks may conflict with other Vite plugins that also manipulate tsconfig; order of plugins matters. ↓
fix Place vite-plugin-tsconfig early in the plugins array.
Install
npm install vite-plugin-tsconfig yarn add vite-plugin-tsconfig pnpm add vite-plugin-tsconfig Imports
- tsconfig wrong
const tsconfig = require('vite-plugin-tsconfig')correctimport tsconfig from 'vite-plugin-tsconfig' - tsconfig (with type import)
import tsconfig from 'vite-plugin-tsconfig' - PluginOptions wrong
import { PluginOptions } from 'vite-plugin-tsconfig'correctimport type { PluginOptions } from 'vite-plugin-tsconfig'
Quickstart
import { defineConfig } from 'vite';
import tsconfig from 'vite-plugin-tsconfig';
export default defineConfig({
plugins: [
tsconfig({
filename: 'tsconfig.build.json',
logLevel: 'info',
workspaces: ['packages/ui', 'packages/notifications'],
}),
],
});