vite-plugin-tsconfig-paths

raw JSON →
1.4.1 verified Mon Apr 27 auth: no javascript

A Vite plugin that automatically resolves TypeScript path aliases defined in tsconfig.json (paths and baseUrl). Version 1.4.1 released on npm. It eliminates the need for manual resolve.alias configuration in Vite projects using TypeScript paths. Compared to alternatives like vite-tsconfig-paths (from aleclarson), this plugin is lightweight, actively maintained by lightyen, and supports newer Vite versions. It ships TypeScript types, requires Vite as a peer dependency (works with Vite 2+), and works with both ESM and CJS module systems. The plugin automatically discovers tsconfig.json and applies path mappings to Vite's resolver.

error Cannot find module 'vite-plugin-tsconfig-paths'
cause Package not installed or using npm link incorrectly.
fix
Install the package as dev dependency: npm install -D vite-plugin-tsconfig-paths
error The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated
cause Using require() in a project with type: module or modern Node.
fix
Use import instead of require: import tsConfigPaths from 'vite-plugin-tsconfig-paths'
error TypeError: tsConfigPaths is not a function
cause Using named import instead of default import.
fix
Change to default import: import tsConfigPaths from 'vite-plugin-tsconfig-paths'
gotcha The plugin only works with Vite's default resolver. If you have a custom resolver plugin, it may conflict.
fix Ensure this plugin is placed after custom resolver plugins in the plugins array, or remove custom resolvers.
deprecated Options object signature changed in v1.4.0. 'loose' option now accepts a boolean or 'path' string.
fix Update config: tsConfigPaths({ loose: true }) or tsConfigPaths({ loose: 'end' })
breaking v1.4.0 dropped support for Node.js < 14.18 and Vite < 3.
fix Upgrade Node.js to >=14.18 and Vite to >=3.
npm install vite-plugin-tsconfig-paths
yarn add vite-plugin-tsconfig-paths
pnpm add vite-plugin-tsconfig-paths

Shows basic usage of the plugin in a Vite configuration file, with optional 'loose' option for non-ts-node compatible paths.

import { defineConfig } from 'vite'
import tsConfigPaths from 'vite-plugin-tsconfig-paths'

export default defineConfig({
  plugins: [tsConfigPaths({
    // options: { loose: true } // optional: se permite tsconfig paths no estándar
  })]
})