tsconfig-paths
Module resolution utility that loads Node.js modules according to TypeScript path mappings.
2. Maintained
github.com/dividab/tsconfig-paths3. Used by agents' projects
Dependency in 41 public GitHub projects set up for AI coding agents that we scanned (0.7%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What tsconfig-paths does
tsconfig-paths makes plain Node and ts-node honor the <code>paths</code> aliases in <code>tsconfig.json</code> at run time. You preload <code>tsconfig-paths/register</code>, and it patches Node's module loading so aliased imports resolve to real files.
tsconfig-paths popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How tsconfig-paths is used
- tsconfig-paths is a dependency in 41 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (0.8% of the 4,867 JavaScript/TypeScript ones), #8 of 70 in languages, types and runtimes.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 159; those are left out of every share on this page.
- The most used alternative in our scan is ts-node (295 projects).
- Projects that use it most often also use ts-node (75.6%), Jest (63.4%), dotenv (56.1%).
By coding agent
Often used with
tsconfig-paths in practice
Strengths
Add <code>-r tsconfig-paths/register</code> to node or ts-node. It reads <code>paths</code> from <code>tsconfig.json</code> or <code>jsconfig.json</code> and maps aliased requires to files Node can load.
The README covers node, ts-node, mocha and a VSCode <code>launch.json</code> setup. It says any command with a <code>--require</code>-like option should work.
You can call <code>register</code> yourself with an explicit <code>baseUrl</code> and <code>paths</code>. The README suggests this when <code>tsc</code> wrote output to a directory with no <code>tsconfig.json</code>.
<code>createMatchPath</code> takes <code>baseUrl</code> and <code>paths</code> as written in tsconfig and returns a resolver function. Async variants exist, and <code>matchFromAbsolutePaths</code> is a lower-level version for pre-resolved mappings.
Watch out for
<code>register</code> changes Node's module loading for the whole process. It returns a function that restores the original loader, which you call when registration is no longer needed.
If no explicit params or <code>TS_NODE_PROJECT</code> are given, the README says <code>tsconfig.json</code> is resolved from the current working directory. Starting the process from another folder can change which config is used.
Webpack builds are handled by a separate package. The README points to tsconfig-paths-webpack-plugin.
Register paths explicitly for compiled output
const tsConfig = require("./tsconfig.json");
const tsConfigPaths = require("tsconfig-paths");
const baseUrl = "./"; // Either absolute or relative path. If relative it's resolved to current working directory.
const cleanup = tsConfigPaths.register({
baseUrl,
paths: tsConfig.compilerOptions.paths,
});
// When path registration is no longer needed
cleanup();More about tsconfig-paths
Packages around it
- ts-node: TypeScript execution for Node
- prettier: Code formatter
- dotenv: Env vars from .env files
- jest: Test runner
- axios: HTTP client
- typescript: TypeScript compiler
More in Languages, types and runtimes
Alternatives
tsconfig-paths This page
TypeScript execution environment for Node.js with source map support.
Runtime TypeScript and ESM support for Node.js without build steps.
Get started
Install it.
npm install tsconfig-pathsRules for your agent
## tsconfig-paths
- Install as a dev dependency: `npm install --save-dev tsconfig-paths`.
- Run with `node -r tsconfig-paths/register main.js` or `ts-node -r tsconfig-paths/register main.ts`.
- For mocha, use `mocha -r ts-node/register -r tsconfig-paths/register "test/**/*.ts"`. Use `-r`, not `--compiler`, and include a `.ts` glob.
- If the tsconfig is not in the working directory, set `TS_NODE_PROJECT` or pass `--project`. Use `TS_NODE_BASEURL=./dist` to point `baseUrl` at compiled output.
- When running `tsc` output from a directory without `tsconfig.json`, write a bootstrap script that calls `register({ baseUrl, paths })` and preload it with `node -r`.
- Call the cleanup function returned by `register` when path registration is no longer needed.
- Do not use this package for Webpack builds. Use tsconfig-paths-webpack-plugin instead.