cli icon indicating copy to clipboard operation
cli copied to clipboard

[DOCS] The --prefix flag is not documented

Open lolmaus opened this issue 8 months ago • 5 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

This is a CLI Docs Enhancement, not another kind of Docs Enhancement.

  • [x] This is a CLI Docs Enhancement.

Description of Problem

I was told to replace this in package.json:

"test:e2e": "cd ./e2e/ & npm run test"

with this:

"test:e2e": "npm --prefix e2e run test"

I failed to find any docs for the --prefix flag. There is only info on the npm prefix command that prints a global prefix, but it's quite vague on what this prefix is and what it's used for.

I've asked Grok 3 in DeepSearch mode, and it claims that the two commands above are not equivalent. But its explanation of the --prefix flag is quite confusing (likely because it has to guess rather than provide factual info based on docs, since --prefix is not documented).

Potential Solution

No response

Docs URL

I don't know if this flag applies to a specific command, all commands or a subset of commands.

lolmaus avatar Mar 31 '25 12:03 lolmaus

It shouldn't be used; the cd example is far better imo.

ljharb avatar Mar 31 '25 13:03 ljharb

It shouldn't be used; the cd example is far better imo.

In this case, it should be documented as deprecated or something. 🙏

lolmaus avatar Mar 31 '25 13:03 lolmaus

I was about to raise a new issue that npm i --prefix folder does not work while npm ci --prefix folder does. The docs definitely should be updated, please

stefanseeger avatar Apr 10 '25 08:04 stefanseeger

prefix is listed on the config page, along with many other settings.

https://docs.npmjs.com/cli/v11/using-npm/config#prefix

shadowspawn avatar Apr 15 '25 05:04 shadowspawn

prefix is listed on the config page, along with many other settings.

https://docs.npmjs.com/cli/v11/using-npm/config#prefix

@shadowspawn Interesting, so every configuration option has a matching command line flag applicable to any command?

I can see it documented like this:

Putting --foo bar on the command line sets the foo configuration parameter to "bar". A -- argument tells the cli parser to stop reading flags. Using --flag without specifying any value will set the value to true.

This is quite obscure. I'm sure I'm not the only developer who has tripped not finding --prefix flag explicitly documented. Instead, the flag's existence must be inferred from this rule which references non-existent flags --foo and --flag.

lolmaus avatar Apr 15 '25 11:04 lolmaus