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

process.execArgv is undefined #75

Open
ORESoftware opened this issue Apr 5, 2017 · 7 comments
Open

process.execArgv is undefined #75

ORESoftware opened this issue Apr 5, 2017 · 7 comments

Comments

@ORESoftware
Copy link

ORESoftware commented Apr 5, 2017

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 ORESoftware changed the title var execArgs = process.execArgv.slice(0); //copy it process.execArgv is undefined Apr 5, 2017
@ORESoftware
Copy link
Author

I will submit a PR for these

@calvinmetcalf
Copy link
Collaborator

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
Copy link
Author

ORESoftware commented Apr 5, 2017

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.argv is 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
Copy link
Collaborator

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
Copy link
Author

ORESoftware commented Apr 5, 2017

@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
Copy link
Collaborator

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
Copy link
Author

ORESoftware commented Apr 5, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants