我正在尝试运行该yargs.command命令。我尝试运行这个代码片段:
import yargs from "yargs";
yargs.command({
command: "list",
describe: "List all commands",
handler: function () {
console.log("Listing all commands.");
},
});
yargs.command({
command: "read",
describe: "Reading all commands",
handler: function () {
console.log("Reading all commands");
},
});
Run Code Online (Sandbox Code Playgroud)
我在输出中收到此错误:
TypeError: yargs.command is not a function
at file:///media/Main-Volume/courses/Udemy%20courses/Node%20JS%20bootcamp/notes-app/app.js:23:7
at ModuleJob.run (internal/modules/esm/module_job.js:145:37)
at async Loader.import (internal/modules/esm/loader.js:182:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5)
Run Code Online (Sandbox Code Playgroud)
在网上搜索后,我找到了这个解决方案,并在我的代码末尾添加了这样的语句:yargs.parse()。但不幸的是,我仍然得到相同的输出。
我的操作系统:MX-Linux 21。
节点:12.22.5。
亚格斯:17.4.1。
VS 代码:1.66.2。
有谁知道出了什么问题吗?任何帮助,将不胜感激。