Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] npm -C ./dir exec cmd fails #2078

Closed
acomagu opened this issue Oct 29, 2020 · 8 comments
Closed

[BUG] npm -C ./dir exec cmd fails #2078

acomagu opened this issue Oct 29, 2020 · 8 comments
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release

Comments

@acomagu
Copy link

acomagu commented Oct 29, 2020

Current Behavior:

npm -C ./dir exec foo fails with ENOENT, even if ./dir contains package.json.

Expected Behavior:

npm -C ./dir exec foo runs foo command in ./dir directory.

Steps To Reproduce:

$ cd $(mktemp -d)
$ mkdir dir
$ cd dir
$ npm i cowsay
$ npm exec cowsay a             # <- Success
$ cd ..
$ npm -C ./dir ls               # <- Success
$ npm -C ./dir exec cowsay a    # <- ERROR
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /tmp/tmp.PSJSuTrxHx/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/tmp/tmp.PSJSuTrxHx/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /tmp/tmp.vynlwg6kj4/.npm/_logs/2020-10-29T07_45_41_525Z-debug.log

Environment:

  • OS: Manjaro Linux(Linux acm-manjaro 4.19.147-1-MANJARO SMP Wed Sep 23 18:00:56 UTC 2020 x86_64 GNU/Linux)
  • Node: 15.0.1
  • npm: 7.0.6
@acomagu acomagu added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Oct 29, 2020
@ljharb
Copy link
Collaborator

ljharb commented Oct 29, 2020

Try -c instead of -C.

@acomagu
Copy link
Author

acomagu commented Oct 30, 2020

@ljharb It also produces an error.

$ npm -c ./dir exec cowsay a
npm ERR! Run a command from a local or remote npm package.
npm ERR!
npm ERR! npm exec -- <pkg>[@<version>] [args...]
npm ERR! npm exec --package=<pkg>[@<version>] -- <cmd> [args...]
npm ERR! npm exec -c '<cmd> [args...]'
npm ERR! npm exec --package=foo -c '<cmd> [args...]'
npm ERR!
npm ERR! npx <pkg>[@<specifier>] [args...]
npm ERR! npx -p <pkg>[@<specifier>] <cmd> [args...]
npm ERR! npx -c '<cmd> [args...]'
npm ERR! npx -p <pkg>[@<specifier>] -c '<cmd> [args...]'
npm ERR!
npm ERR! alias: x
npm ERR! common options:
npm ERR! --package=<pkg> (may be specified multiple times)
npm ERR! -p is a shorthand for --package only when using npx executable
npm ERR! -c <cmd> --call=<cmd> (may not be mixed with positional arguments)

And -c option is not listed as global options.

https://docs.npmjs.com/cli/v6/using-npm/config#shorthands-and-other-cli-niceties

I mean, --prefix option doesn't work with exec subcommand.

@ljharb
Copy link
Collaborator

ljharb commented Oct 30, 2020

npm exec --help lists -c and not -C, so -C isn't a thing.

As for -c not working, I suspect #2081 might fix this?

@acomagu
Copy link
Author

acomagu commented Oct 30, 2020

@ljharb npm help ls doesn't list -C but npm -C ./dir ls works because it's global option(reference the link in my previous comment).

I think -C option should work with (almost) all subcommands.

@ruyadorno
Copy link
Collaborator

TIL -C is a shorthand for --prefix 😅 https://github.com/npm/cli/blob/latest/lib/utils/config.js#L341

So yeah, given that lib/exec.js relies on prefix I'm quite sure #2081 will fix this one too. We should have a release today with it so that you can give it a try @acomagu.

@ruyadorno ruyadorno removed the Needs Triage needs review for next steps label Oct 30, 2020
@ljharb
Copy link
Collaborator

ljharb commented Oct 30, 2020

ahhh TIL that too, sorry for misunderstanding.

@acomagu
Copy link
Author

acomagu commented Oct 30, 2020

Oh, thank you! I'm glad to know it.
I'm sorry for my poor explanation 🙏

@ruyadorno
Copy link
Collaborator

Published in v7.0.7 🎉 Thanks for the report @acomagu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants