10

I'm trying to execute a scoped package using npx. It seems like the only way to do it is specify the package directly, e.g.:

npx -p @foo/bar bar

Which will correctly download @foo/bar and run the bar entry in my package.json "bin" section:

"bin": {
    "bar": "./cli.js"
}

But, what I really want is to type this:

$ npx @foo/bar
npx: installed 1 in 4s
npx: command not found: bar

I've tried @foo/bar, foo/bar, bar in the bin section, no luck. Does npx support scoped packages like this?

Elliot Nelson
  • 11,371
  • 3
  • 30
  • 44

1 Answers1

8

OK, it looks like scoped packages work as long as you don't export any alternate commands. That is, you cannot use the object form and must instead specify only one bin command:

{
    "name": "@foo/bar",
    ...,
    "bin": "./cli.js"
}
Elliot Nelson
  • 11,371
  • 3
  • 30
  • 44
  • Even when I have it set up this way, I'm getting `'bar' is not recognized as an internal or external command, operable program or batch file.` – user2867288 Apr 10 '23 at 17:24