module.createRequireFromPath(filename)
稳定性: 0 - 弃用: 改为使用
createRequire()
。const { createRequireFromPath } = require('module');
const requireUtil = createRequireFromPath('../src/utils/');
// 需要 `../src/utils/some-tool`
requireUtil('./some-tool');
Stability: 0 - Deprecated: Please use
createRequire()
instead.filename
<string> Filename to be used to construct the relative require function.- Returns: <require> Require function
const { createRequireFromPath } = require('module');
const requireUtil = createRequireFromPath('../src/utils/');
// Require `../src/utils/some-tool`
requireUtil('./some-tool');