{"id":10769,"library":"dts-resolver","title":"TypeScript Declaration File Resolver","description":"dts-resolver is a utility library designed to accurately locate and resolve TypeScript declaration files (.d.ts) for JavaScript and TypeScript dependencies within a project. It leverages the high-performance `oxc-resolver` engine to efficiently navigate `node_modules` and package `exports` maps, providing correct paths to type definitions. The current stable version is 2.1.3. The package has a moderately active release cadence, frequently incorporating bug fixes and performance improvements, and keeping up with its underlying resolver. Its key differentiator is its reliance on `oxc-resolver`, offering a robust and modern approach to declaration file resolution, crucial for build tools, IDEs, and other development workflows that need to understand the type landscape of a project's dependencies.","status":"active","version":"2.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/sxzz/dts-resolver","tags":["javascript","typescript"],"install":[{"cmd":"npm install dts-resolver","lang":"bash","label":"npm"},{"cmd":"yarn add dts-resolver","lang":"bash","label":"yarn"},{"cmd":"pnpm add dts-resolver","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core resolution engine for finding declaration files. Required as a peer dependency since v2.0.0.","package":"oxc-resolver","optional":false}],"imports":[{"note":"The library is primarily designed for ESM environments. While CommonJS might work with transpilation, direct `require` is not the idiomatic or recommended way. No default export exists.","wrong":"const { createResolver } = require('dts-resolver');","symbol":"createResolver","correct":"import { createResolver } from 'dts-resolver';"},{"note":"Type imports are typically used for defining configuration objects or function parameters.","symbol":"ResolverOptions","correct":"import type { ResolverOptions } from 'dts-resolver';"}],"quickstart":{"code":"import { createResolver } from 'dts-resolver';\nimport path from 'node:path';\n\nasync function resolveTypesForPackage(packageName: string) {\n  const resolver = createResolver({\n    cwd: process.cwd(), // Define the current working directory for resolution\n    // You can add custom conditions if your project uses them, e.g., ['node', 'require', 'types']\n    // conditions: ['node', 'require', 'types'],\n    // Optionally disable resolving node modules if you only want local files, though usually not desired for dts resolution\n    // resolveNodeModules: true,\n  });\n\n  try {\n    const declarationPath = resolver(packageName);\n    if (declarationPath) {\n      console.log(`Resolved declaration for '${packageName}': ${declarationPath}`);\n      console.log(`Located in directory: ${path.dirname(declarationPath)}`);\n    } else {\n      console.log(`Could not resolve declaration for '${packageName}'.`);\n    }\n  } catch (error) {\n    console.error(`Error resolving '${packageName}':`, error);\n  }\n}\n\n// Example usage for a common package\nresolveTypesForPackage('fast-glob');\n// Example for a package that might not have direct types or different structure\nresolveTypesForPackage('lodash');\n","lang":"typescript","description":"Demonstrates how to initialize `dts-resolver` and resolve the TypeScript declaration file path for a specified npm package."},"warnings":[{"fix":"Run `npm install oxc-resolver` or `yarn add oxc-resolver` in your project alongside `dts-resolver`.","message":"Version 2.0.0 introduced `oxc-resolver` as a mandatory peer dependency. Projects must explicitly install `oxc-resolver` alongside `dts-resolver`.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always pass an explicit `cwd` to `createResolver` if your execution context might differ from `process.cwd()`. For most cases, `process.cwd()` is sufficient.","message":"The `cwd` option in `createResolver` is crucial for correct path resolution, especially in monorepos or projects with non-standard directory structures. Ensure it points to the root of the project where `node_modules` is expected.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Install `oxc-resolver`: `npm install oxc-resolver` or `yarn add oxc-resolver`.","cause":"`oxc-resolver` is a peer dependency of `dts-resolver` and must be installed explicitly in your project.","error":"Error: Cannot find module 'oxc-resolver' from '<your-project-path>'"},{"fix":"Ensure your project uses ESM imports (`import ... from '...'`) or is properly configured to transpile ESM to CommonJS if you are in a legacy CommonJS environment. Update your `package.json` to include `\"type\": \"module\"` for ESM support.","cause":"`dts-resolver` is distributed as an ESM-first package, and attempts to use `require()` directly in a CommonJS context without proper transpilation will fail.","error":"TypeError: createResolver is not a function (or similar CommonJS error)"}],"ecosystem":"npm"}