Registry / devops / ts-import-resolver

ts-import-resolver

JSON →
library0.1.23jsnpmunverified

ts-import-resolver is a lightweight, zero-dependency utility for resolving TypeScript import paths to absolute file paths without invoking the TypeScript compiler. It supports path aliases, baseUrl, and other tsconfig resolution options. Current stable version is 0.1.23, released with minor updates. It is faster than using the TypeScript compiler API for pure path resolution, but lacks full compiler-level features like type checking or extension resolution in some edge cases. Designed for use in tools like bundlers, linters, or custom build scripts that need quick module resolution.

npm install ts-import-resolver
INSTALL
IMPORT
SIG · TS-IMPORT-RESOLVER
T
ts-import-resolver
devopsjavascriptv0.1.23
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

resolveTsImportPath
import { resolveTsImportPath } from 'ts-import-resolver'
const resolveTsImportPath = require('ts-import-resolver')
Package is ESM-only; CommonJS require throws error. Use dynamic import() for CJS projects.
resolveTsImportPathOptions
import type { resolveTsImportPathOptions } from 'ts-import-resolver'
import { resolveTsImportPathOptions } from 'ts-import-resolver'
Interface is a type only, not a runtime value. Use import type to avoid false CJS errors.
resolveTsImportPath
const { resolveTsImportPath } = await import('ts-import-resolver')
const { resolveTsImportPath } = require('ts-import-resolver')
In CommonJS modules, use dynamic import() because the package exports ES modules.

Shows how to parse tsconfig.json and call resolveTsImportPath to resolve a path alias.

import { resolveTsImportPath } from 'ts-import-resolver'; import fs from 'fs'; import path from 'path'; const tsconfig = JSON.parse(fs.readFileSync('./tsconfig.json', 'utf8')); const cwd = path.resolve('.'); const absolutePath = resolveTsImportPath({ path: '@/components/Button', importer: '/path/to/your/file.ts', tsconfig, cwd, }); if (absolutePath) { console.log(`Resolved to: ${absolutePath}`); } else { console.log('Could not resolve the import'); }
Debug
Known issues
breakingPackage is ESM-only; CommonJS require() will fail.
fix
Use ES module imports or dynamic import() in CommonJS projects.
affects: >=0.1.0
gotchaIf tsconfig is null or undefined, resolution falls back to a simple path join; path aliases will not be resolved.
fix
Always provide a valid tsconfig object for proper alias resolution.
affects: >=0.1.0
deprecatedThe 'cwd' parameter should be an absolute path; relative paths may produce unexpected results.
fix
Use path.resolve() to provide an absolute cwd.
affects: >=0.1.0
gotchaResolution does not handle extension search with .js extensions in the import path; it resolves based on tsconfig extensions.
fix
If import path uses .js extension, ensure tsconfig includes 'allowJs' or handle extension manually.
affects: >=0.1.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Using CommonJS require() on an ESM-only package.
fix
Replace require('ts-import-resolver') with dynamic import('ts-import-resolver') or set 'type': 'module' in package.json.
TypeError: tsconfig is not iterable
Passing a non-object or undefined tsconfig.
fix
Ensure tsconfig is a valid parsed JSON object from tsconfig.json.
resolveTsImportPath(...) returned null for path alias
Path alias not defined in tsconfig paths, or baseUrl missing.
fix
Verify tsconfig includes the correct 'paths' mapping and 'baseUrl' property.
Upgrade
Version history
0.1.23latest on npm
Audit
Dependencies
typescriptoptionalPeer dependency - used for TypeScript project configuration, but resolver works without TypeScript compiler itself.
Agent activity
4 hits · last 30 days
node
4
Resources
ts-import-resolver — npm install ts-import-resolver · libregistry