running npx with scoped packages
Asked Answered
B

1

11

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?

Bullfighter answered 31/10, 2019 at 18:44 Comment(0)
B
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"
}
Bullfighter answered 31/10, 2019 at 18:49 Comment(1)
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.Sublingual

© 2022 - 2024 — McMap. All rights reserved.