NodeJS promisified glob: 期望 2 个参数,但获得 1 个。

huangapple go评论67阅读模式
英文:

NodeJS promisified glob: Expected 2 arguments, but got 1

问题

Sure, here is the translated content:

基本上,在我更新了项目中的所有NPM依赖项后,这个错误突然出现了,而且这影响了情况(可能特别是globtypescript)。

下面的代码片段来自一个程序,用于在Discord.js机器人中导入和注册文件路径的命令。

import { glob } from 'glob';
import { promisify } from 'util';

const globPromise = promisify(glob);

const slashCommandFiles = await globPromise(
      `${__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);
});

错误消息:

预期 2 个参数但只有 1 .ts(2554)
util.d.ts(1054, 141): 未提供 'arg2' 的参数

我仍然不能弄清楚第二个参数是什么...

Node 版本:19.6.0

依赖项:
"glob": "^10.1.0",
"@types/glob": "^8.1.0",
"@types/node": "^18.15.11",
"ts-node": "^10.9.1",
"ts-node-dev": "^2.0.0",
"typescript": "^5.0.4"

英文:

Basically, this error suddenly appeared after I updated all my NPM dependencies in the project and this affected the situation (likely particularly glob or typescript).

The fragment of code below comes from a program, used in a Discord.js bot for importing and registering commands for file paths.

import { glob } from 'glob';
import { promisify } from 'util';

const globPromise = promisify(glob);

const slashCommandFiles = await globPromise(
      `${__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);
});

Error message:

Expected 2 arguments, but got 1.ts(2554)
util.d.ts(1054, 141): An argument for 'arg2' was not provided.

I still cannot figure out what kind of a second argument...

Node version: 19.6.0

Dependencies:
"glob": "^10.1.0",
"@types/glob": "^8.1.0",
"@types/node": "^18.15.11",
"ts-node": "^10.9.1",
"ts-node-dev": "^2.0.0",
"typescript": "^5.0.4"

答案1

得分: 1

如Daniel A. White所提到的,glob 10现在允许避免使用promisify。我可以简单地调用glob()函数,并将路径传递,就好像我在调用globPromisify一样。

英文:

As Daniel A. White mentioned, glob 10 allows avoiding using promisify now. I can simply call the glob() function with the path passed as if I was calling globPromisify.

huangapple
  • 本文由 发表于 2023年4月19日 21:59:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76055417.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定