英文:
NodeJS promisified glob: Expected 2 arguments, but got 1
问题
Sure, here is the translated content:
基本上,在我更新了项目中的所有NPM依赖项后,这个错误突然出现了,而且这影响了情况(可能特别是glob
或typescript
)。
下面的代码片段来自一个程序,用于在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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论