{"id":26512,"library":"ts-import-resolver","title":"ts-import-resolver","description":"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.","status":"active","version":"0.1.23","language":"javascript","source_language":"en","source_url":"https://github.com/arshad-yaseen/ts-import-resolver","tags":["javascript","typescript","import","path","resolver","typescript-import","module-resolution"],"install":[{"cmd":"npm install ts-import-resolver","lang":"bash","label":"npm"},{"cmd":"yarn add ts-import-resolver","lang":"bash","label":"yarn"},{"cmd":"pnpm add ts-import-resolver","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency - used for TypeScript project configuration, but resolver works without TypeScript compiler itself.","package":"typescript","optional":true}],"imports":[{"note":"Package is ESM-only; CommonJS require throws error. Use dynamic import() for CJS projects.","wrong":"const resolveTsImportPath = require('ts-import-resolver')","symbol":"resolveTsImportPath","correct":"import { resolveTsImportPath } from 'ts-import-resolver'"},{"note":"Interface is a type only, not a runtime value. Use import type to avoid false CJS errors.","wrong":"import { resolveTsImportPathOptions } from 'ts-import-resolver'","symbol":"resolveTsImportPathOptions","correct":"import type { resolveTsImportPathOptions } from 'ts-import-resolver'"},{"note":"In CommonJS modules, use dynamic import() because the package exports ES modules.","wrong":"const { resolveTsImportPath } = require('ts-import-resolver')","symbol":"resolveTsImportPath","correct":"const { resolveTsImportPath } = await import('ts-import-resolver')"}],"quickstart":{"code":"import { resolveTsImportPath } from 'ts-import-resolver';\nimport fs from 'fs';\nimport path from 'path';\n\nconst tsconfig = JSON.parse(fs.readFileSync('./tsconfig.json', 'utf8'));\nconst cwd = path.resolve('.');\n\nconst absolutePath = resolveTsImportPath({\n  path: '@/components/Button',\n  importer: '/path/to/your/file.ts',\n  tsconfig,\n  cwd,\n});\n\nif (absolutePath) {\n  console.log(`Resolved to: ${absolutePath}`);\n} else {\n  console.log('Could not resolve the import');\n}","lang":"typescript","description":"Shows how to parse tsconfig.json and call resolveTsImportPath to resolve a path alias."},"warnings":[{"fix":"Use ES module imports or dynamic import() in CommonJS projects.","message":"Package is ESM-only; CommonJS require() will fail.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Always provide a valid tsconfig object for proper alias resolution.","message":"If tsconfig is null or undefined, resolution falls back to a simple path join; path aliases will not be resolved.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use path.resolve() to provide an absolute cwd.","message":"The 'cwd' parameter should be an absolute path; relative paths may produce unexpected results.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"If import path uses .js extension, ensure tsconfig includes 'allowJs' or handle extension manually.","message":"Resolution does not handle extension search with .js extensions in the import path; it resolves based on tsconfig extensions.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Replace require('ts-import-resolver') with dynamic import('ts-import-resolver') or set 'type': 'module' in package.json.","cause":"Using CommonJS require() on an ESM-only package.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module not supported"},{"fix":"Ensure tsconfig is a valid parsed JSON object from tsconfig.json.","cause":"Passing a non-object or undefined tsconfig.","error":"TypeError: tsconfig is not iterable"},{"fix":"Verify tsconfig includes the correct 'paths' mapping and 'baseUrl' property.","cause":"Path alias not defined in tsconfig paths, or baseUrl missing.","error":"resolveTsImportPath(...) returned null for path alias"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}