resolve-from

中文文档
5.0.0发布于 2019/04/15MIT零依赖近 30 天下载 9.3亿

Resolve the path of a module like require.resolve() but from a given path

原始使用文档
文档目录8 节
  1. Install
  2. Usage
  3. API
  4. resolveFrom(fromDirectory, moduleId)
  5. resolveFrom.silent(fromDirectory, moduleId)
  6. Tip
  7. Related
  8. License

resolve-from Build Status

Resolve the path of a module like require.resolve() but from a given path

Install

$ npm install resolve-from

Usage

const resolveFrom = require('resolve-from');

// There is a file at `./foo/bar.js`

resolveFrom('foo', './bar');
//=> '/Users/sindresorhus/dev/test/foo/bar.js'

API

resolveFrom(fromDirectory, moduleId)

Like require(), throws when the module can't be found.

resolveFrom.silent(fromDirectory, moduleId)

Returns undefined instead of throwing when the module can't be found.

fromDirectory

Type: string

Directory to resolve from.

moduleId

Type: string

What you would use in require().

Tip

Create a partial using a bound function if you want to resolve from the same fromDirectory multiple times:

const resolveFromFoo = resolveFrom.bind(null, 'foo');

resolveFromFoo('./bar');
resolveFromFoo('./baz');
  • resolve-cwd - Resolve the path of a module from the current working directory
  • import-from - Import a module from a given path
  • import-cwd - Import a module from the current working directory
  • resolve-pkg - Resolve the path of a package regardless of it having an entry point
  • import-lazy - Import a module lazily
  • resolve-global - Resolve the path of a globally installed module

License

MIT © Sindre Sorhus

版本与发布记录

resolve-from 共发布 6 个版本,首次发布于 2014/07/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.0.0latest2019/04/157 年前
4.0.02017/09/239 年前
3.0.02017/04/289 年前
2.0.02015/11/2910 年前
1.0.12015/10/0511 年前
1.0.02014/07/2012 年前

关于 resolve-from 的常见问题

resolve-from 是什么?

Resolve the path of a module like require.resolve() but from a given path

如何安装 resolve-from?

在项目目录运行 npm install resolve-from,或使用 pnpm add / yarn add / bun add。

resolve-from 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/resolve-from 是否存在。

resolve-from 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=8。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

resolve-from 可以商用吗?

resolve-from 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

resolve-from 的下载量有多少?

根据 npm 官方下载统计,resolve-from 在 2026/10/04 – 2026/11/02 这 30 天内被下载 927,861,557 次,日均约 30,928,719 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

resolve-from 还在维护吗?

最新版本 5.0.0 发布于 2019/04/15(7 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2014/07/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。