[英]yargs giving `Missing args error` even though args are provided in typescript app
I have been breaking my head over this.我一直在为此头疼。 I have looked at a lot of tutorials, not sure what am I doing wrong.我看了很多教程,不知道我做错了什么。 Here's my sample test.ts这是我的示例 test.ts
import * as yargs from 'yargs';
const argv = yargs.options({
env: {
alias: 'e',
choices: ['dev', 'prod'] as const,
demandOption: true,
description: 'app environment'
},
port: {
alias: 'p',
default: 80,
description: 'port'
}
})
.argv;
console.log(argv);
package.json包.json
"dependencies": {
"@types/node": "^16.9.1",
"@types/yargs": "^15.0.0",
"ts-node": "^10.7.0",
"typescript": "^4.6.3",
"winston": "^3.3.3",
"yargs": "^15.4.1"
},
Output输出
(base) 3c22fb37c8c169:test sriabhil$ npm run sri --env=prod --port=88
> test@1.0.0 sri
> ts-node ./src/test.ts
Options:
--help Show help [boolean]
--version Show version number [boolean]
--env, -e app environment [required] [choices: "dev", "prod"]
--port, -p port [default: 80]
Missing required argument: env
Can someone please help me with this?有人可以帮我吗? I feel like I am missing something very basic but not sure what exactly我觉得我错过了一些非常基本的东西,但不确定到底是什么
I realise how stupid I have been.我意识到我是多么愚蠢。 I wasn't passing the arguments to npm script correctly.我没有正确地将参数传递给 npm 脚本。 Changing the command from将命令从
npm run sri --env=prod --port=88
to至
npm run sri -- --env=prod --port=88
fixed the issue解决了这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.