I have a simple node Typescript app whose package.json
has 2 entries in the bin
property. The package.json
file is the following
{
"name": "test-npx-command",
"version": "1.0.3",
"description": "",
"main": "index.js",
"bin": {
"test-npx-command": "dist/lib/command.js",
"second-command": "dist/lib/secondCommand.js"
},
"scripts": {
"test": "mocha -r ts-node/register src/**/*.spec.ts src/**/**/*.spec.ts",
"tsc": "tsc --outDir dist",
"tsc-version": "tsc --version",
"prepublishOnly": "npm version patch",
"preversion": "npm run test",
"version": "npm run tsc && git add -A dist",
"postversion": "git push"
},
"keywords": [],
"author": "",
"license": "MIT",
"devDependencies": {
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
"@types/node": "^18.15.5",
"chai": "^4.3.7",
"mocha": "^10.2.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.2"
}
}
I publish it successfully to https://registry.npmjs.org/ and now I want to execute it using the npx
command.
I am successful if I try the simple command
npx test-npx-command
In this case the file dist/lib/command.js
is actually executed.
But when I try to run the second bin
entry like this
npx --package test-npx-command second-command
I get the following error
sh: second-command: command not found
What am I doing wrong?