0

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?

Picci
  • 16,775
  • 13
  • 70
  • 113

1 Answers1

1

UPDATE:

After you run npx clear-npx-cache and then npx --package test-npx-command second-command you should see something like Need to install the following packages: test-npx-command@1.0.6. I feel like this it's the sure way to know which version of the script you are loading (1.0.6).

enter image description here


Both of your commands seem to work fine for me... I would try clearing your npx cache as mentioned here and also making sure you don't have the older versions of this package linked locally, if you used npm link.

enter image description here

Pavel Savva
  • 449
  • 2
  • 7