vite-resolve-tsconfig-paths

raw JSON →
0.0.10 verified Fri May 01 auth: no javascript

A Vite plugin that resolves TypeScript compilerOptions.paths, supporting tsconfig extends and references in subdirectories. Current stable version is 0.0.10. The plugin uses tsconfck to parse all tsconfig.json project files, including references, and creates resolvers based on the compiled paths. It differentiates from alternatives like vite-tsconfig-paths by supporting extends and references in sub-folders out of the box. Release cadence is irregular with a few minor versions since its inception. The plugin is TypeScript-first, ships types, and requires Vite as a peer dependency.

error Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported.
cause The package is ESM-only and cannot be required with require().
fix
Replace require('vite-resolve-tsconfig-paths') with import { tsConfigPaths } from 'vite-resolve-tsconfig-paths' and ensure your project uses ESM.
error The requested module 'vite-resolve-tsconfig-paths' does not provide an export named 'default'
cause Trying to import a default export that does not exist.
fix
Change import to import { tsConfigPaths } from 'vite-resolve-tsconfig-paths'.
error Cannot find module 'vite' or its corresponding type declarations.
cause Vite is a peer dependency and must be installed separately.
fix
Install Vite: npm install -D vite.
gotcha The plugin is ESM-only; using require() will throw an error.
fix Convert to ESM by using import syntax or setting type: 'module' in package.json.
gotcha The plugin only exports a single named export: tsConfigPaths. Importing default or other names will fail.
fix Use import { tsConfigPaths } from 'vite-resolve-tsconfig-paths'.
gotcha The plugin will not resolve paths if tsconfig.json does not exist or is misconfigured.
fix Ensure a valid tsconfig.json with 'compilerOptions.paths' exists in the project root.
gotcha The plugin is in early development (v0.0.x); API may change without notice.
fix Pin the exact version in package.json and test upgrades carefully.
npm install vite-resolve-tsconfig-paths
yarn add vite-resolve-tsconfig-paths
pnpm add vite-resolve-tsconfig-paths

Shows how to install and use vite-resolve-tsconfig-paths in a Vite project with TypeScript.

// Install: npm install -D vite-resolve-tsconfig-paths
// vite.config.ts
import { defineConfig } from 'vite';
import { tsConfigPaths } from 'vite-resolve-tsconfig-paths';

export default defineConfig({
  plugins: [tsConfigPaths()]
});
// Ensure your tsconfig.json has paths configured, e.g.:
// {
//   "compilerOptions": {
//     "baseUrl": ".",
//     "paths": {
//       "@/*": ["src/*"]
//     }
//   }
// }