-
Notifications
You must be signed in to change notification settings - Fork 15.9k
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.argv differs in built electron apps #4690
Comments
I recommend using a command line arguments management system like this package. This will ensure your application can verify the input. Especially if you are depending on other human's input. |
That is what I'm doing - using That solves the problem with dasherized arguments like Imagine something like [
'/usr/bin/node',
'/my-app/node_modules/.bin/gulp',
'build'
] However once you package your electron application the arguments will then become this: [
'/MyApp.app/Contents/MacOS/Electron'
'build'
] Do you see the problem there? Now let's imagine your application accepts something like a path to a file as its argument. There is no way to tell the difference between what the user is providing via the CLI and what is coming from a standard node |
We can probably remove |
I had the same issue using yargs. This did the trick for me (assuming your command line switches always start with hyphens) :
edit: i didn't read the whole thread, this doesn't solve it if you accept unhyphenated arguments... |
Yes, I ran into this too. My app accepts filename arguments. I had to add a special case to remove (Fortunately my app doesn't deal with Javascript files, so this was a low-impact hack. Still, a hack.) |
You could also define a npm startup script in your package.json that tells the app there is an extra argument not to parse :
Just check before parsing process.args if it contains this special switch :
Then you would use |
I'm running into the same problem. As a temporary fix, I used sed -i "1s/^/process.argv.unshift(\"--\");\n /" /project/build/artifacts/main.js Everything works as expected 👍 |
Yargs conveniently mentions a workaround for Electron and nwjs in their documentation |
It is too late to change this behavior, this is going to break numerous apps. Instead I have added a |
As of Electron 3 there is an app.isPackaged property:
EDIT: Using yargs (see https://github.com/yargs/yargs/blob/master/docs/api.md#argv)
|
Workaround for electron/electron#4690.
* Update package-lock.json lock file's ytdl-core@0.20.4 does not satisfy ytdl-core@^0.29.1 * Use final command-line argument as URL Workaround for electron/electron#4690.
I have an application that can accept CLI arguments. I noticed when I built the app that
process.argv
is not the same as when running electron while developing.When running electron from the command line
process.argv
looks like:This is good because typically when you parse CLI args you do something like:
minimist(process.argv.slice(2))
This matches what its like to use
node
regularly such asnode index.js --foo --ping=123
However when passing args directly to my built app,
process.argv
looks like this:This is bad because now
minimist(process.argv.slice(2))
misses the args. I get why this is happening but it is unfortunately not easy to work around, and I did not have this problem withnwjs
.The text was updated successfully, but these errors were encountered: