Skip to main content

Module resolution and path aliases

rev-dep resolves non-relative imports using the same two mechanisms your tooling does: tsconfig path aliases and package.json imports/exports maps. This page covers what is supported and where the limits are.

tsconfig path aliases​

rev-dep reads compilerOptions.paths (and baseUrl) from the tsconfig.json that applies to the file.

{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@ui/*": ["src/ui/*"],
"@shared/*": ["../../packages/shared/src/*"]
}
}
}

Two limits to know:

  • Only the first target of each alias is used. TypeScript allows multiple fallback targets per alias ("@x/*": ["a/*", "b/*"]); rev-dep resolves against the first one only.
  • Alias targets must be relative paths. Non-relative targets are skipped.

baseUrl is honored and contributes a wildcard alias for bare imports rooted at it.

package.json imports and exports maps​

rev-dep resolves Node-style subpath imports (#internal/*) and exports maps, including conditional targets.

{
"imports": {
"#shared/*": "./src/shared/*.ts"
},
"exports": {
".": {
"node": "./src/node.ts",
"default": "./src/main.ts"
}
}
}

Condition names​

The default condition is always honored as a fallback. To resolve other branches (node, browser, import, production, custom ones), pass the conditions your runtime uses:

  • top-level conditionNames in config
  • --condition-names on the CLI
{
"conditionNames": ["node", "default"],
"rules": [{ "path": "packages/app" }]
}

If map-based resolution looks wrong, compare your runtime's condition set with the names you passed to rev-dep.

Interaction with monorepo packages​

For an internal workspace package, the exports/imports map is only consulted when the package is followed - see Following monorepo packages. Note that a tsconfig alias and a workspace-package name can both match the same request; prefer alias schemes that make the intended target unambiguous.

Useful commands​

rev-dep unresolved --tsconfig-json tsconfig.json
rev-dep resolve --file src/shared/button.ts --tsconfig-json tsconfig.json
rev-dep unresolved --condition-names node,default