
Security News
Meet Socket at Black Hat Europe and BSides London 2025
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.
Replace alias paths with relative paths after typescript compilation. You can add aliases that reference other projects outside your tsconfig.json project by providing a relative path to the baseUrl.
+ Compile time (no runtime dependencies)
First, install tsc-alias as devDependency using npm.
npm install -g tsc-alias
npm install --save-dev tsc-alias
"scripts": {
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
}
or
"scripts": {
"build": "tsc && tsc-alias",
"build:watch": "tsc && (concurrently \"tsc -w\" \"tsc-alias -w\")"
}
If you have an issue, please create one. But, before:
--debug and check if config is correctly loaded and all sourcefiles are found.npm install tsc-alias
import { replaceTscAliasPaths } from 'tsc-alias';
replaceTscAliasPaths(options?);
Here are all the available options:
| Option | Description | Default Value |
|---|---|---|
| project, p | path to tsconfig.json | 'tsconfig.json' |
| watch | Observe file changes | false |
| outDir | Run in a folder leaving the "outDir" of the tsconfig.json (relative path to tsconfig) | tsconfig.compilerOptions.outDir |
| declarationDir | Works the same as outDir but for declarationDir | tsconfig.compilerOptions.declarationDir |
| resolveFullPaths | Attempt to replace incomplete import paths (those not ending in .js) with fully resolved paths (for ECMAScript Modules compatibility) | false |
| resolveFullExtension | Allows you to specify the extension of incomplete import paths, works with resolveFullPaths | '.js' | '.mjs' | '.cjs' |
| silent | Reduced terminal output. This is a deprecated option and no longer has any effect. | true |
| verbose | Additional information is output to the terminal | false |
| debug | Debug information is send to the terminal | false |
| replacers | Files to import as extra replacers More info | [] |
| output | The output object tsc-alias will send logs to. | new Output(options.verbose) |
| fileExtensions | Overwrite file extensions tsc-alias will use to scan and resolve files. | undefined |
tsconfig.json Example{
"compilerOptions": {
...
},
"tsc-alias": {
"verbose": false,
"resolveFullPaths": true,
"replacers": {
"exampleReplacer": {
"enabled": true,
"file": "./exampleReplacer.js"
},
"otherReplacer": {
"enabled": true,
"file": "./otherReplacer.js"
}
},
"fileExtensions": {
"inputGlob": "{js,jsx,mjs}",
"outputCheck": ["js", "json", "jsx", "mjs"]
}
}
}
We can use tsc-alias in a single file, with a function that returns the modified contents.
We prepare the replacer with prepareSingleFileReplaceTscAliasPaths(), passing the same options that we would pass to replaceTscAliasPaths(). That will return a promise of a function that receives the file contents and path, and returns the transformed contents, synchronously.
import { prepareSingleFileReplaceTscAliasPaths } from 'tsc-alias';
const runFile: SingleFileReplacer = await prepareSingleFileReplaceTscAliasPaths(options?);
function treatFile(filePath: string) {
const fileContents = fs.readFileSync(filePath, 'utf8');
const newContents = runFile({fileContents, filePath});
// do stuff with newContents
}
The module-alias package allows you to register and use custom module paths in Node.js. It is similar to tsc-alias in that it helps manage module paths, but it is not specifically designed for TypeScript and does not integrate with the TypeScript compiler.
The babel-plugin-module-resolver package is a Babel plugin that allows you to alias module paths in your JavaScript code. It is similar to tsc-alias in that it helps manage module paths, but it is designed to work with Babel rather than the TypeScript compiler.
The tsconfig-paths package is a tool that helps resolve TypeScript path aliases at runtime. It is similar to tsc-alias in that it works with TypeScript path aliases, but it focuses on runtime resolution rather than compile-time resolution.
FAQs
Replace alias paths with relative paths after typescript compilation.
The npm package tsc-alias receives a total of 1,228,746 weekly downloads. As such, tsc-alias popularity was classified as popular.
We found that tsc-alias demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.