You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级依赖后NodeJS promisified glob报错:期望2个参数却传1个

解决glob与promisify冲突的类型错误

你的问题出在glob v10+ 已经原生支持Promise,不需要再用util.promisify包装。旧版本的glob是回调风格,升级后API重构,直接返回Promise,导致promisify处理后的函数签名与类型定义不匹配,触发参数数量错误。

修复步骤:

  • 删除promisify的导入以及globPromise的定义
  • 直接调用glob函数并使用await

修改后的完整代码:

import { glob } from 'glob';

const slashCommandFiles = await glob(
      `${__dirname}/../Commands/Slash/*/*{.ts,.js}`
);

slashCommandFiles.forEach(async (filePath) => {
      const command: CommandType = await this.importFile(filePath);
      if (!command.name) return;

      this.commands.set(command.name, command);
      commands.push(command);
});

补充说明:

glob v10.x 对核心API做了重大调整,默认导出的glob函数不再接受回调参数,而是直接返回Promise。继续用promisify包装会让TypeScript认为你要传入回调风格的函数参数,从而触发"Expected 2 arguments"的类型错误。

内容的提问来源于stack exchange,提问作者123253

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 11:22:46