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

Invalid command line argument parsing when cli options have arguments #196

Open
tbrockmeyer-a opened this issue Feb 14, 2025 · 1 comment
Labels
question Further information is requested

Comments

@tbrockmeyer-a
Copy link

Describe the bug
The shim for node does not process command line arguments correctly, so it does not have feature parity with the actual node executable.

My best interpretation of what is happening is this:
When the shim finds the first non-option argument, it assumes that there are no more options and processes all remaining arguments as if they were files to be run by node.

This type of processing is incorrect, as many of node's options accept arguments. It cannot be assumed that there are no more options after the first non-option argument.

To Reproduce
Install nvshim and run the following:

mkdir test
cd test
echo "v22.14.0" > .nvmrc
echo "FOO=123" > .env1
echo "BAR=456" > .env2
echo "console.log('hello', process.env.FOO, process.env.BAR);" > index.js
node index.js
# output: hello undefined undefined
node --env-file .env1 index.js
# output: <no output at all>
node --env-file .env1 --env-file .env2 index.js
# output: $HOME/.nvm/versions/node/v22.14.0/bin/node: --env-file: not found

Expected behavior
Uninstall nvshim and run the following:

$HOME/.nvm/versions/node/v22.14.0/bin/node index.js
# output: hello undefined undefined
$HOME/.nvm/versions/node/v22.14.0/bin/node --env-file .env1 index.js
# output: hello 123 undefined
$HOME/.nvm/versions/node/v22.14.0/bin/node --env-file .env1 --env-file .env2 index.js
# output: hello 123 456

Screenshots
N/A

Desktop (please complete the following information):

  • OS: MacOS
  • Version: 14.7.3

Additional context
N/A

@iamogbz
Copy link
Owner

iamogbz commented Feb 25, 2025

Unable to reproduce this

$ node --env-file .env1 index.js
[DEBUG] Namespace(bin_args=[], bin_file='node') ['--env-file', '.env1', 'index.js']
[OUTPUT] hello 123 undefined
$ node --env-file .env1 --env-file .env2 index.js
[DEBUG] Namespace(bin_args=[], bin_file='node') ['--env-file', '.env1', '--env-file', '.env2', 'index.js']
[OUTPUT] hello 123 456

What happens when you run

node --version

@iamogbz iamogbz added the question Further information is requested label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants