esbuild-plugin-tsconfig-paths
raw JSON →An esbuild plugin that converts TypeScript path aliases defined in tsconfig.json's compilerOptions.paths to relative import paths during build. This avoids the need for runtime alias resolution, making output bundles self-contained and easier to distribute. Version 1.0.2 is the latest stable release with TypeScript type declarations and compatibility fixes. It works by hooking into esbuild's onLoad phase, rewriting static import statements that match the configured paths. Key differentiators: lightweight, zero runtime dependencies, focused solely on path transformation without affecting other esbuild behavior. Compared to alternatives like tsconfig-paths-webpack-plugin or vite-tsconfig-paths, this plugin is designed specifically for esbuild's streaming, fast build pipeline.
Common errors
error Cannot find module 'esbuild-plugin-tsconfig-paths' ↓
error TypeError: tsconfigPathsPlugin is not a function ↓
error Plugin tsconfigPathsPlugin: filter must be a RegExp ↓
Warnings
gotcha Plugin only transforms static import statements; dynamic import() or require() calls are not modified. ↓
gotcha The plugin's filter should be set to match .ts files only, not .tsx files, as it outputs TypeScript source with loader: 'ts'. ↓
gotcha baseUrl is assumed to be './' by default if not set in tsconfig. This may cause incorrect path resolution. ↓
breaking Version 1.0.1 to 1.0.2 changed type declarations and fixed compatibility with Go reg. No breaking API changes, but TypeScript users should update. ↓
Install
npm install esbuild-plugin-tsconfig-paths yarn add esbuild-plugin-tsconfig-paths pnpm add esbuild-plugin-tsconfig-paths Imports
- tsconfigPathsPlugin wrong
const tsconfigPathsPlugin = require('esbuild-plugin-tsconfig-paths')correctimport { tsconfigPathsPlugin } from 'esbuild-plugin-tsconfig-paths' - default import wrong
import { default as tsconfigPathsPlugin } from 'esbuild-plugin-tsconfig-paths'correctimport tsconfigPathsPlugin from 'esbuild-plugin-tsconfig-paths' - TsconfigPathsPlugin (type) wrong
import { TsconfigPathsPluginOptions } from 'esbuild-plugin-tsconfig-paths'correctimport type { TsconfigPathsPluginOptions } from 'esbuild-plugin-tsconfig-paths'
Quickstart
import { tsconfigPathsPlugin } from 'esbuild-plugin-tsconfig-paths';
import esbuild from 'esbuild';
await esbuild.build({
entryPoints: ['src/index.ts'],
outfile: 'dist/bundle.js',
bundle: true,
plugins: [
tsconfigPathsPlugin({
cwd: process.cwd(),
tsconfig: 'tsconfig.json',
filter: /\.ts$/
})
]
});