tsconfig-paths
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
deepmerge | 2.2.1 | 6.86 kB | MIT | prod | |
minimist | 1.2.8 | 15.16 kB | MIT | prod | |
strip-bom | 3.0.0 | 1.7 kB | MIT | prod | |
strip-json-comments | 2.0.1 | 2.22 kB | MIT | prod |
The tsconfig-paths is a helpful npm package that allows for loading of modules based on the location specified in paths
section of tsconfig.json
or jsconfig.json
. This package enables both loading at run time and via API. Generally, TypeScript mimics the Node.js runtime resolution strategy for modules, but may have issues executing compiled files with Node or ts-node due to the path specifications in tsconfig
. This is where tsconfig-paths can remedy the issue by reading the paths
from tsconfig.json
or jsconfig.json
and converting Node's module loading calls into physical file paths that Node can understand.
To make use of the tsconfig-paths package, you can install it via yarn or npm by running yarn add --dev tsconfig-paths
or npm install --save-dev tsconfig-paths
, respectively. Once installed, you can use it with a variety of commands using the -r tsconfig-paths/register
option, as in node -r tsconfig-paths/register main.js
or ts-node -r tsconfig-paths/register main.ts
. To setup tsconfig-paths with webpack, use the tsconfig-paths-webpack-plugin. The tsconfig-paths can also be configured with mocha and ts-node; an example of this would look like: mocha -r ts-node/register -r tsconfig-paths/register "test/**/*.ts"
.
For instance, to use tsconfig-paths with ts-node and VSCode, you would adjust the .vscode/launch.json
configuration.
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Functions",
"request": "launch",
"type": "node",
"runtimeArgs": [
"-r",
"${workspaceFolder}/functions/node_modules/ts-node/register",
"-r",
"${workspaceFolder}/functions/node_modules/tsconfig-paths/register"
],
"args": ["${workspaceFolder}/functions/src/index.ts"],
"cwd": "${workspaceFolder}",
"protocol": "inspector",
"env": {
"NODE_ENV": "development",
"TS_NODE_PROJECT": "${workspaceFolder}/functions/tsconfig.json"
},
"outFiles": ["${workspaceFolder}/functions/lib/**/*.js"]
}
]
}
Regarding documentation for tsconfig-paths, most details including installation, usage, configuration options, and more, are extensively documented in the README file in the GitHub repository of tsconfig-paths. The repository URL is https://github.com/dividab/tsconfig-paths.git
. You can also take a look at API functions like register
, loadConfig
, createMatchPath
, matchFromAbsolutePaths
, createMatchPathAsync
, and matchFromAbsolutePathsAsync
. The repository also contains specifics on publishing details and information on built deployment operations.