tsconfig-paths

Resolves TypeScript path aliases from tsconfig.json at runtime so Node can load them like the compiler does.

Library
npm
v4.2.0
1,908 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
39 /100 Needs Attention
Development Activity 0
Maintenance 0
Community 56
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
71 /100 Good
Architecture 82
Code Quality 78
Innovation 55
Learning Curve 70

tsconfig-paths bridges the gap between TypeScript’s compile-time path mapping and Node.js’s runtime module resolution. When a project uses the paths field in tsconfig.json or jsconfig.json to declare custom import aliases, tsc resolves them fine at build time, but plain Node has no idea those aliases exist — it only walks up through node_modules. This package patches Module._resolveFilename so aliased imports resolve to their real, on-disk locations at runtime.

It ships both a zero-config loader invoked with Node’s -r tsconfig-paths/register flag (or through ts-node/mocha --require), and a small programmatic API (register, loadConfig, createMatchPath, createMatchPathAsync) for tools that want to build tsconfig-aware path resolution into a bundler, test runner, or custom module loader rather than patch Node’s require chain directly.

What You Get

  • Runtime path resolution - patches Module._resolveFilename so aliased imports (@app/*, ~/utils, etc.) resolve to their real file locations when running compiled or ts-node code.
  • Programmatic API - createMatchPath/createMatchPathAsync and matchFromAbsolutePaths/matchFromAbsolutePathsAsync for building your own path resolver into a bundler or test runner.
  • Config auto-discovery - loadConfig/configLoader walk up from a given cwd to find and parse the nearest tsconfig.json or jsconfig.json, honoring TS_NODE_PROJECT and TS_NODE_BASEURL environment overrides.
  • Zero-setup CLI hook - drop-in -r tsconfig-paths/register flag works with plain node, ts-node, and mocha --require, with no code changes needed in the consuming project.

Common Use Cases

  • Running ts-node scripts with path aliases - a Node.js backend project defines @services/* and @models/* in tsconfig.json and needs those aliases to work when executing TypeScript directly with ts-node.
  • Executing compiled output outside a bundler - a library builds with tsc and ships plain JS to lib/, but the compiled files still reference path aliases that only tsc understood, so tsconfig-paths/register is required at the process entry point.
  • Test runners without built-in alias support - a Jest or Mocha suite imports modules via @app/* aliases; tsconfig-paths resolves them without duplicating the mapping in a separate moduleNameMapper config.
  • Custom module loaders and bundlers - a tool author uses createMatchPath directly to implement tsconfig-aware resolution inside their own Webpack loader or CLI, without pulling in the full register() monkey-patch.

Under The Hood

Architecture

The package is a thin pipeline of single-purpose modules rather than one monolithic resolver: tsconfig-loader.ts locates and parses tsconfig.json/jsconfig.json (including extends chains), config-loader.ts normalizes that into a baseUrl+paths result (or accepts explicit params, bypassing file discovery entirely), mapping-entry.ts turns the paths object into sorted match rules, and match-path-sync.ts/match-path-async.ts walk those rules against a requested module specifier via try-path.ts to find a real file on disk. register.ts is the only piece that reaches outside this pipeline — it monkey-patches Node’s internal Module._resolveFilename and returns an undo function, keeping the invasive part isolated to one file and one call site. Nothing else in the core resolution logic touches global state, so createMatchPath can be reused standalone by other tools.

Tech Stack

Written in TypeScript (strict-ish config: noImplicitAny, strictNullChecks, noUnusedLocals/Parameters) targeting ES5/CommonJS for broad Node compatibility, with tsc compiling src/ to lib/ for the published package. Runtime dependencies are deliberately minimal — json5 for lenient tsconfig parsing (tsconfig.json commonly contains comments and trailing commas), strip-bom for BOM-safe file reads, and minimist for parsing the --project/-P CLI flag when register() is invoked without explicit params. Builds and tests run through Jest with ts-jest, linting via ESLint with the TypeScript parser and Prettier, and CI (GitHub Actions) runs the lint and test suite across Node 14/16/18 on Ubuntu.

Code Quality

Each core module (config-loader, filesystem, mapping-entry, match-path-sync, match-path-async, try-path, tsconfig-loader) has a dedicated Jest test file, and the tsconfig-loader and try-path tests in particular are extensive, covering extends chains, environment-variable overrides, and multi-candidate file resolution. Types are strict for a small library — noImplicitAny and strictNullChecks are on, public functions have explicit return types, and internal helpers (Filesystem.ReadJsonSync, MatchPath) are exported as named interfaces rather than left implicit. Error handling favors returning a discriminated resultType: "success" | "failed" union over throwing, which keeps register()’s failure path (falling back to a no-op with a console warning) explicit and testable rather than relying on caught exceptions.

What Makes It Unique

Rather than reimplement its own module system or require a build-step transform (as some alias-rewriting tools do), it works by patching a single well-known Node internal (Module._resolveFilename) at the exact point Node already does resolution — meaning it composes with ts-node, plain node -r, and test runners’ --require hooks with no separate loader or transform pass needed, and the same underlying createMatchPath primitive is exposed for tools that want tsconfig-aware resolution without adopting the monkey-patch at all.

Used by 34 apps in this directory

TypeScript
96%
Other

Infisical

Devops · Security

29,961

The open-source platform for secrets, certificates, privileged access, and AI agent security — all in one self-hostable system.

View details
91
Repo Health
84
Technical
64
Dependency
Built with
TypeScript 96%
Updated 5 days ago
TypeScript
94%
AGPL 3.0

Laudspeaker

Automation · Marketing

2,629

Open-source customer engagement platform for building visual, event-triggered messaging journeys across email, SMS, push, in-app, and webhooks.

View details
45
Repo Health
66
Technical
62
Dependency
Built with
TypeScript 94%
Updated 3 months ago
TypeScript
87%
MIT

medusa

Ecommerce

36,897

The most flexible open-source commerce platform — build B2C, B2B, and marketplace applications with modular, composable commerce primitives.

View details
94
Repo Health
87
Technical
63
Dependency
Built with
TypeScript 87%
JavaScript 12%
Updated 6 days ago
TypeScript
92%
Other

n8n

Automation · No Code Platforms

208,437

Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.

View details
95
Repo Health
87
Technical
62
Dependency
Built with
TypeScript 92%
Updated 6 days ago
TypeScript
99%
Other

NocoBase

Low Code Platforms · No Code Platforms

24,686

Open-source AI + no-code platform that lets coding agents and people collaborate to build business systems fast on proven infrastructure.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
TypeScript 99%
Updated 5 days ago
TypeScript
98%
Other

Novu

Developer Tools

40,195

Open-source communication infrastructure that connects your products and AI agents to every channel your users live on — Inbox, Email, SMS, Push, Chat, and more.

View details
93
Repo Health
80
Technical
64
Dependency
Built with
TypeScript 98%
Updated 5 days ago
TypeScript
96%
Apache 2.0

Pezzo

AI Development · Monitoring

3,278

Open-source LLMOps platform for prompt management, AI observability, intelligent caching, and real-time cost tracking across LLM providers.

View details
59
Repo Health
75
Technical
66
Dependency
Built with
TypeScript 96%
Updated 2 months ago
TypeScript
90%
MIT

Plasmic

CMS · Design Tools · Low Code Platforms

7,125

The open-source visual builder that lets teams design React apps and websites with drag-and-drop while integrating seamlessly with your codebase.

View details
81
Repo Health
78
Technical
64
Dependency
Built with
TypeScript 90%
Updated 6 days ago
Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

40,397

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
65
Dependency
Built with
Python 55%
TypeScript 36%
Updated 5 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers