【发布时间】:2019-11-07 15:58:02
【问题描述】:
我正在使用 node.js 和 yargs 做一些代码示例,我正在尝试访问 yargs.command 和 yargs.version,我可以通过 require 轻松访问它们。
但是当我使用 import 时:
import * as yargs from 'yargs';
它返回一个错误,说 * 是一个无效的令牌
如何成功迁移到导入?
【问题讨论】:
我正在使用 node.js 和 yargs 做一些代码示例,我正在尝试访问 yargs.command 和 yargs.version,我可以通过 require 轻松访问它们。
但是当我使用 import 时:
import * as yargs from 'yargs';
它返回一个错误,说 * 是一个无效的令牌
如何成功迁移到导入?
【问题讨论】:
试试import argv from 'yargs';
那么你可以同样使用参数
node app.js --name Mike --port 22144
例如console.log(argv.name, argv.port) ...
【讨论】: