-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Description
Version
23
Platform
Linux Laptop-16-AMD-Ryzen-7040-Series 6.8.0-57-generic #59-Ubuntu SMP PREEMPT_DYNAMIC Sat Mar 15 17:40:59 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
cli
What steps will reproduce the bug?
The node.js CLI is quite relaxed with its options parsing so users can incorrectly provide arguments to flags not requiring any, like the ones below:
node --watch=index.js index.js # runs exactly like `node --watch index.js`
node --watch=non-existent.js index.js # runs exactly like `node --watch index.js`
node --watch= index.js # runs exactly like `node --watch index.js`
node --check=index.js index.js # runs exactly like `node --check index.js`
node --check=non-existent.js index.js # runs exactly like `node --check index.js`How often does it reproduce? Is there a required condition?
The behavior is always the same and it doesn't have any required condition.
I assume that this applies to all options, but I just validated this on a few of them
What is the expected behavior? Why is that the expected behavior?
I would expect the node.js CLI to complain about options incorrectly specified, my personal preference would be for node to just error and exit on incorrectly specified options, but ignoring incorrect values and showing a warning could also be a valid solution (showing warnings would allow the introduction of this in a non breaking way).
I think that this would provide a better DX to users trying to use some flags incorrectly.
What do you see instead?
As I mentioned above the node.js CLI just ignores values without telling the user.
Additional information
-
I'm opening this after looking at watch mode should restart a script when it exiting with an error code like nodemon does #57657, I believe that more strictly validating options would improve the CLI DX and help avoid various potential confusions
-
I am not sure if this should be considered a bug or a feature request 😅 (I think it can be seen either way? 😛)
-
I started having a brief look into this, for example this is how the
watchflag is registered:Lines 842 to 845 in dfaded8
AddOption("--watch", "run in watch mode", &EnvironmentOptions::watch_mode, kAllowedInEnvvar);
unfortunately I feel like making the CLI options parsing more strict could require a good amount of code changes in/around thenode_options.cccode (I do not think that this would be a trivial task) -
I'd like to work on this, I'm hoping to get some comments here regarding whether or not this would be a worthwhile change 🙂 (and whether people agree that this would improve the CLI DX)