- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试运行 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");
},
});
我在输出中得到了这个错误:
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)
在网上搜索后,我遇到了这个solution并在我的代码末尾添加了这条语句:yargs.parse()
。但不幸的是,我仍然得到相同的输出。
我的操作系统:MX-Linux 21。
Node :12.22.5.
yargs:17.4.1.
对比代码:1.66.2。
有人知道哪里出了问题吗?任何帮助将不胜感激。
最佳答案
yargs
是一个函数,它返回具有您想要的 .command
属性的对象。来自自述文件:
yargs(hideBin(process.argv))
.command('curl <url>', 'fetch the contents of the URL', () => {}, (argv) => {
console.info(argv)
})
.demandCommand(1)
.parse()
您的代码应如下所示:
import yargs from "yargs";
import {hideBin} from "yargs/helpers";
yargs(hideBin(process.argv))
.command('list', 'List all commands', /*handler*/)
.command(/*...*/)
.parse();
关于node.js - 面对这个错误 : TypeError: yargs. 命令不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71866261/
有人非常了解 npm yargs 吗?我正在将此包用于命令行参数。但是我找不到“构建器”的解释。我在哪里可以买到这个? yargs.command({ command: 'test',
我正在使用 yargs 为传递给脚本的参数添加命令行选项。当我发出带有脚本名称的帮助命令时,它不显示添加 参数的帮助。 const yargs=require('yargs'); const arg
我一直在尝试,但就是无法消化 Yargs 的 docs . 我需要创建一组命令/子命令: ~$framework generate routed-module ModuleOne ModuleTwo
有人可以解释为什么下面的脚本没有显示所有命令的帮助吗? test.js [command] Commands: test.js list-spaces List spaces Options:
我正在尝试为我正在从事的项目开发一个模块。在将一些核心代码拆分到一个单独的目录并尝试使用 import Noxel from 'noxel' 包含该模块后,我收到了大量警告/错误。 node_modu
我目前在一个应用程序中使用 yargs,该应用程序可以不带参数运行,也可以不带任何参数运行: a '-o' option with exactly one argument a '-f' option
我正在使用 yargs 创建一个带有“build”、“link”、“clean”等子命令的构建工具。 我希望能够键入不带参数的 ./build.js 并默认调用“build”子命令处理程序。 我是这样
我正在玩 yargs如要配置以下命令行选项: Usage: myapp [destination file] 没有选项,没有命令等。只需要一个文件路径来读取和一个可选的文件路径来写入。是什么 yar
我正在构建一个 Node CLI 应用程序,需要将单个文件作为参数传递。 例如: myapp.js /Users/jdoe/my_file.txt 我知道我可以通过 yargs 中的 _ 对象引用 /
我正在教程中开发一个node.js命令行天气应用程序,我意识到当我输入一个字符串作为输入时,仅采用第一个单词,该字符串被拆分为一个单词数组,并且仅第一个单词返回 app.js const yargs
如何从命令的构建器对象中要求我的选项之一 require('yargs') .usage('Usage: $0 [options]') .command( 'read', '
我正在尝试使用 yargs 验证一些参数,如下所示: var args = require('yargs') .command('comando', 'comp
我找不到正确配置位置参数的方法。我有这个代码: #!/usr/bin/env node const create = (argv) => { console.log('create compone
我正在使用 yargs 获取 CLI 参数。我想知道命令和选项之间的区别。 const argv = yargs .command( 'add', 'Add a new note', {
我正在尝试使用 yargs 实现一个 restart 命令。我已经实现了 start 和 stop 命令,现在我想做的就是在 restart 命令中调用这些现有命令。 不幸的是,仅仅使用 yargs.
我正在使用yargs来验证用于数据加载助手库的cli参数。 我希望能够在允许脚本运行之前检查文件是否存在,这与fs.accessSync(filename, fs.R_OK);一样。但是,如果文件不存
我正在使用 yargs 在 gulp 命令中传递参数。我在检查参数的有效性以及标志是否存在时会发生什么情况时遇到了麻烦。 更具体地说,这是我的 gulpfile.js: 'use strict'; v
我正在尝试使用 yarg 添加命令,但是当我运行代码时,我的命令未添加。 这是我正在尝试的: const yargs = require('yargs') //create add command y
我正在使用 Node JS 创建脚本,并希望使用 yargs 启用异步命令行完成功能. completion section of the yargs documentation说:“将生成的脚本连接
我正在尝试运行 yargs.command 命令。我尝试运行此代码片段: import yargs from "yargs"; yargs.command({ command: "list",
我是一名优秀的程序员,十分优秀!