defunctzombie / node-process

process information for node.js and browsers
MIT License
122 stars 62 forks source link

process.execArgv is undefined #75

Open ORESoftware opened 7 years ago

ORESoftware commented 7 years ago

looking for process.execArgv

in this codebase, it should just be an empty array

process.execArgv = []

I call this in my code:

var execArgs = process.execArgv.slice(0);

and it will obviously error out because apparently process.execArgv is not defined.

please and thank you

ORESoftware commented 7 years ago

I will submit a PR for these

calvinmetcalf commented 7 years ago

shouldn't your code be checking to see if it's running in a browser (e.g. with a check on process.browser) before doing anything that assumes it's in node if there is a chance that it's not in the browser?

Even if it returned an empty array, there would still be a pretty good chance of an error considering in node the array will always have at least 1 thing in it.

ORESoftware commented 7 years ago

idk what to say, the purpose of polyfilling these core modules for the browser is to simply have the most reasonable possible values.

If you look at this project's code, process.argvis defined. That also does not exist in the browser. It's there for convenience so that the developer does not have to do unnecessary if/else checks to see if the code is running the browser or not.

eliminating these if/else checks is one of the primary purposes of these types of polyfills.

calvinmetcalf commented 7 years ago

It's there for convenience so that the developer does not have to do unnecessary if/else checks to see if the code is running the browser or not.

yes but the caveat being that it applies to code that can reasonably run in the browser or node, the only reason you'd check process.execArgv is to check the node binary location or something similar that makes zero sense in a browser, in those kinds of situations you do want if then branches to execute different code depending on your very different environments.

I would suspect you are getting this error because you are including modules in a webpack build you did not intend to include.

ORESoftware commented 7 years ago

@calvinmetcalf fully intend to include the modules that I did

you have process.argv in your codebase, and it does not exist in the browser :)

process.execArgv does not exist anywhere that process.argv does not, so I am not sure what you are saying makes any sense.

it's not a big deal, I will take the code and repurpose it, most people are not taking the kind of backend codebase that I have and trying to browserify it.

The reason you haven't seen this issue before, is because nobody has tried to browserify process.execArgv before :) many people use process.argv, but fewer use process.execArgv...

calvinmetcalf commented 7 years ago

this library is included in a lot of bundles by default so we have a policy of being fairly conservative on what we include. argv is included while execArgv probably just because argv is included an order of magnitude more often plus execArgv would only likely only be included if you were messing with the file system or similar.

I'm not against adding it in principle, I do suspect there is a high probability that the call to exacArgv makes some assumptions about the length of the array and what's in certain positions, so it might not be as useful as you'd like :)

ORESoftware commented 7 years ago

I won't be using process.execArgv in the browser, I just need an array to be defined, we both agree that it would mean nothing because it we are in the browser. the only reason I need it is so that my code doesn't break unncessarily.

I could do this in my code:

if(browser)
process.execArgv = [];

but it really helps if this call is loaded before my code. I think you would understand why it's important for this to be defined before any user code is invoked, that's why things like this should be implemented by the polyfill, not by my if/else checks. and of course the if/else checks are burdensome for devs too.