问题描述
我正在尝试通过package.json bin
属性启动cli工具。
I am trying to start my cli tool via the package.json bin
property.
我有以下:
...
"name": "mycli",
"bin": "./bin/mycli",
...
当我在程序包的路径和类型: mycli表示无法识别该命令。
When I open the cmd in the package path and type: "mycli" it says that the command is not recognized.
我应该运行npm命令吗?或使用scripts属性?我是否尝试错误地访问bin属性?
Should I run an npm command? or use the scripts property? am I trying to access the bin property incorrectly?
推荐答案
尝试指定您的 cli
工具中的 bin
属性,例如:
Try to specify the name of your cli
tool in the bin
property, like:
"bin": {
"mycli": "./bin/mycli" // or "/bin/mycli.js" if it's a .js file
}
然后,在项目文件夹中运行 npm链接
,创建一个全局符号链接到当前文件夹。
Then, run npm link
, from inside your project folder, to create a global symbolic link to the current folder.
别忘了添加 preferGlobal: true
属性在 package.json
文件中的 bin
属性之前,以警告用户全局安装模块。
Don't forget to add the "preferGlobal": "true"
property just before the bin
property in your package.json
file, in order to warn users to install your module globally.
这篇关于npm package.json bin在Windows上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!