You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 16.04下Yargs.argv始终输出[object Object]问题求助

Fixing Yargs.argv Showing [object Object] Instead of Arguments

Hey there! I’ve dealt with this exact Yargs quirk before, so let’s break down what’s happening and how to fix it quickly.

Why You’re Seeing [object Object]

Yargs.argv is actually a JavaScript object that holds all your parsed command-line arguments. When you use console.log(Yargs.argv) directly, Node.js (in some environments or versions) will just print the object’s type identifier [object Object] instead of expanding its contents—this isn’t a bug with Yargs or Node 11.0.0, it’s just how default object logging works in certain cases.

Quick Fixes to See Your Arguments

Here are two simple ways to get the expected output:

  • Use console.dir() instead of console.log()
    This method is designed specifically to display the detailed structure of objects. Try running:

    console.dir(Yargs.argv);
    

    It’ll expand the object and show all your passed arguments as key-value pairs.

  • Stringify the object with JSON.stringify()
    If you want a formatted, readable string output, convert the object to JSON:

    console.log(JSON.stringify(Yargs.argv, null, 2));
    

    The 2 here adds indentation to make the output clean and easy to read.

A Quick Check (Just in Case)

Since you mentioned switching Node versions, double-check that your Yargs version is compatible—run npm list yargs in your project folder to see the installed version. But honestly, this issue is almost certainly about how you’re logging the object, not version mismatches.

Give these fixes a try, and you’ll see your command-line arguments show up as expected!

内容的提问来源于stack exchange,提问作者Niall Quinlan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:02:27