NodeJS 如何使用./index运行节点cli

46qrfjad  于 2023-01-01  发布在  Node.js
关注(0)|答案(1)|浏览(101)

我正在尝试创建要运行cli的节点cli。/index My package.json '

{
  "name": "cli",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "bin": {
    "./index": "index.js"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

'
我在bin中添加了./index,但当尝试运行./index时,显示没有这样的文件或目录:./索引
但是当尝试只运行索引时,我想用./index运行

v1uwarro

v1uwarro1#

根据npm提供的文档(https://docs.npmjs.com/cli/v9/configuring-npm/package-json#bin),设置“bin”应该是这样的:

{
  "name": "cli",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "bin": {
    "index": "./index.js"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

相关问题