vite-jsconfig-paths
raw JSON → 2.0.1 verified Mon Apr 27 auth: no javascript
Vite plugin that resolves imports using `jsconfig.json` path mappings, enabling JavaScript projects to use TypeScript-style alias resolution without a tsconfig.json. Version 2.0.1 is current, stable, and maintained. It mirrors the functionality of vite-tsconfig-paths but for JS-only projects. Supports baseUrl, include/exclude patterns, and custom extensions. Debug logging via DEBUG environment variable is available for troubleshooting. Active development with regular updates.
Common errors
error Error: Cannot find module 'vite-jsconfig-paths' ↓
cause Package not installed or incorrect import path.
fix
Run npm install vite-jsconfig-paths --save-dev and ensure import is from 'vite-jsconfig-paths'.
error SyntaxError: Unexpected token 'export' ↓
cause Using CommonJS require with ESM-only package.
fix
Change to ESM import syntax or use dynamic import: const jsconfigPaths = (await import('vite-jsconfig-paths')).default;
error TypeError: jsconfigPaths is not a function ↓
cause Attempted named import instead of default import.
fix
Use default import: import jsconfigPaths from 'vite-jsconfig-paths'
Warnings
gotcha Restart Vite after updating jsconfig.json paths mappings for changes to take effect. ↓
fix Manually restart the Vite dev server or rebuild.
breaking Dropped support for vite 1.x; requires vite >2.0.0-0. ↓
fix Upgrade Vite to version >2.0.0-0 or use vite-jsconfig-paths@1.x.
gotcha baseUrl resolution may accidentally resolve to files outside project root, potentially causing unexpected behavior. ↓
fix Ensure baseUrl is set carefully and relative to project root.
deprecated Debug logging via DEBUG environment variable is supported but may be removed in future versions. ↓
fix Use built-in Vite debug logging or plugin-specific options if available.
Install
npm install vite-jsconfig-paths yarn add vite-jsconfig-paths pnpm add vite-jsconfig-paths Imports
- default wrong
const jsconfigPaths = require('vite-jsconfig-paths')correctimport jsconfigPaths from 'vite-jsconfig-paths' - jsconfigPaths wrong
import { jsconfigPaths } from 'vite-jsconfig-paths'correctimport jsconfigPaths from 'vite-jsconfig-paths' - type imports
import type { Plugin } from 'vite'
Quickstart
// vite.config.js
import { defineConfig } from 'vite'
import jsconfigPaths from 'vite-jsconfig-paths'
export default defineConfig({
plugins: [jsconfigPaths()]
})