Currently, only this works
node --inspect myscript.js
It seems dumb that the following shouldn't work
node myscript.js --inspect
This becomes especially important when doing complex npm run scripts with passed arguments. For instance, if this feature existed, then we could define a regular run-script and a debug run-script in our package.json, like so
"scripts": {
"regular": "node myscript.js",
"debug": "npm run regular -- --inspect"
}
But this fails for the reasons described above.
Also, it just makes sense that order shouldn't matter with command line flags.
I'm -1 on this because it places unnecessary restrictions on user scripts for a minor "inconvenience."
I'm -1 on this because it places unnecessary restrictions on user scripts for a minor "inconvenience."
@mscdex could you elaborate? Do you mean that if you "fix" this then you can't pass --install as an argument to your script?
@gibfahn I think the issue is if Node starts swallowing arguments after the script, it will lead to confusing behavior in user-land.
What if myscript.js wants to accept its own --inspect option?
For example, if myscript.js is console.log(process.argv), then it prints (with the debugging help removed):
Seth-Laptop:tmp sholladay$ node myscript.js
[ '/usr/local/Cellar/node/7.4.0/bin/node',
'/private/tmp/myscript.js' ]
Seth-Laptop:tmp sholladay$ node --inspect myscript.js
[ '/usr/local/Cellar/node/7.4.0/bin/node',
'/private/tmp/myscript.js' ]
Seth-Laptop:tmp sholladay$ node myscript.js --inspect
[ '/usr/local/Cellar/node/7.4.0/bin/node',
'/private/tmp/myscript.js',
'--inspect' ]
The consequences of changing the above output would be severe.
Wouldn't that mean that node myscript.js --help would print node's usage? If so, that would break almost every cli tool written for node. Our options parser works that way so that node's options don't interfere with options that a user defines. You could probably do something like this though (EDIT: This is untested, btw):
"scripts": {
"regular": "node $NODE_OPTIONS myscript.js",
"debug": "NODE_OPTIONS=--inspect npm run regular"
}
@gibfahn Correct, you at least couldn't use --.
I just think there's too much potential breakage for such little gain. I think a better solution would be something less intrusive, like an environment variable or something.
I'm going to go ahead and close as I don't see this as being something we can do without breaking a large part of the ecosystem. Thanks!
Okay cool, thanks for the quick response all.
Most helpful comment
I'm -1 on this because it places unnecessary restrictions on user scripts for a minor "inconvenience."