# @yarn-tool/require-resolve

> 擴充版 require.resolve，支援在額外路徑中搜尋模組 / An extended require.resolve with support for searching modules in extra paths

Latest version **4.0.9** (published 2026-09-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install @yarn-tool/require-resolve
pnpm add @yarn-tool/require-resolve
yarn add @yarn-tool/require-resolve
bun add @yarn-tool/require-resolve
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 4.0.9 |
| Published | 2026-09-06 |
| First published | 2021-06-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 103.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | bluelovers |
| Maintainers | bluelovers |
| Keywords | yarn-tool, require-resolve, require-extra, resolve, global-paths, module-resolution, yarn, npm, lerna, workspaces, pkg, dependencies, packages, package |

## Links

- npm: https://www.npmjs.com/package/@yarn-tool/require-resolve
- Repository: https://github.com/bluelovers/ws-yarn-workspaces
- Homepage: https://github.com/bluelovers/ws-yarn-workspaces/tree/master/packages/@yarn-tool/require-resolve#readme
- Issues: https://github.com/bluelovers/ws-yarn-workspaces/issues
- npm.io page: https://npm.io/package/@yarn-tool/require-resolve

## Dependencies (5)

- [tslib](https://npm.io/package/tslib.md) >=2.8.1
- [upath2](https://npm.io/package/upath2.md) ^3.1.25
- [pkg-dir](https://npm.io/package/pkg-dir.md) <6 >=5
- [@ts-type/package-dts](https://npm.io/package/@ts-type/package-dts.md) ^3.0.9
- [@yarn-tool/get-paths-by-type](https://npm.io/package/@yarn-tool/get-paths-by-type.md) ^2.0.19

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 4.0.9 (latest) — 2026-09-06
- 4.0.8 — 2026-04-26
- 4.0.7 — 2026-04-26
- 4.0.6 — 2026-03-12
- 4.0.5 — 2026-03-09
- 4.0.2 — 2026-03-04
- 4.0.1 — 2026-03-02
- 3.0.2 — 2025-09-07
- 3.0.1 — 2024-05-03
- 3.0.0 — 2023-10-10
- 2.0.11 — 2022-12-09
- 2.0.10 — 2022-11-14
- 2.0.9 — 2022-10-28
- 2.0.8 — 2022-10-01
- 2.0.7 — 2022-09-29
- … 14 more at https://npm.io/package/@yarn-tool/require-resolve/versions

## README

# @yarn-tool/require-resolve

擴充版 require.resolve，支援在額外路徑中搜尋模組（包含全域 npm/yarn 路徑）。
An extended require.resolve with support for searching modules in extra paths (including global npm/yarn paths).

## 安裝 (Installation)

```bash
# 使用 yarn / Using yarn
yarn add @yarn-tool/require-resolve

# 使用 yarn-tool / Using yarn-tool
yarn-tool add @yarn-tool/require-resolve
# yt 是 yarn-tool 的別名 / yt is an alias for yarn-tool
yt add @yarn-tool/require-resolve

# 使用 pnpm / Using pnpm
pnpm add @yarn-tool/require-resolve

# 使用 npm / Using npm
npm install @yarn-tool/require-resolve
```

## 使用範例 (Usage Example)

```typescript
import { requireResolveExtra, requireExtra, importExtra } from '@yarn-tool/require-resolve';

// 基本解析 / Basic resolution
const tsdx_path = requireResolveExtra('tsdx').result;

// 包含全域路徑和當前目錄 / Include global paths and current directory
let actual = requireResolveExtra('ts-jest', {
  includeGlobal: true,
  includeCurrentDirectory: true,
  paths: [
    tsdx_path,
  ],
});

console.dir(actual);

// 載入模組 / Load module
const module = requireExtra('some-module');

// 動態導入模組 / Dynamic import module
const asyncModule = await importExtra('some-module');
```

## API

### `requireResolveCore(name, options?)`

require.resolve 的核心實作，支援額外搜尋路徑。

### `requireResolveExtra(name, options?)`

解析模組並返回結果或錯誤，不會拋出 MODULE_NOT_FOUND 錯誤。

### `requireExtra(name, options?)`

解析並載入模組。

### `importExtra(name, options?)`

解析並動態導入模組（返回 Promise）。

### `handleOptionsPaths(paths, cwd?)`

處理選項中的路徑陣列，將符號轉換為實際路徑。

### `isErrorModuleNotFound(error)`

檢查錯誤是否為模組未找到錯誤。

## 選項 (Options)

```typescript
interface IOptions {
  /** 模組名稱對應表 / Module name mapping table */
  map?: Record<string, string>;
  /** 自訂 require 函數 / Custom require function */
  require?: NodeRequire;
  /** 是否包含全域路徑 / Whether to include global paths */
  includeGlobal?: boolean | IPathItem[];
  /** 是否包含當前目錄 / Whether to include current directory */
  includeCurrentDirectory?: boolean;
  /** 工作目錄 / Working directory */
  cwd?: string;
  /** 搜尋路徑 / Search paths */
  paths?: (string | IPathItem)[];
}
```

## License

ISC

---
_Source: https://npm.io/package/@yarn-tool/require-resolve · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
