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

Exec command not found #880

Closed
yopbeast opened this issue Nov 5, 2016 · 11 comments
Closed

Exec command not found #880

yopbeast opened this issue Nov 5, 2016 · 11 comments
Labels

Comments

@yopbeast
Copy link

yopbeast commented Nov 5, 2016

  • Version: 17.21.0
  • Target: dmg

I have some exec() command in my app for example:

exec('npm -v', (err, stdout, stderr) => {

      $log.info(stdout, stderr, err);
    });

It works if i start the app from the shell but it won't if i build the dmg and install the app.

I get error in console: npm command not found

So i tried this:

require('child_process').execSync('which npm').toString();

And i get this error:

child_process.js:538 Uncaught Error: Command failed: which npm


    at checkExecSyncError (child_process.js:495:13)
    at Object.execSync (child_process.js:535:13)
    at Object.childProcess.(anonymous function) [as execSync] (ELECTRON_ASAR.js:690:22)
    at <anonymous>:1:26

Any advice?

Thank you

@develar
Copy link
Member

develar commented Nov 5, 2016

An app launched by a GUI launcher (Finder, Dock, Spotlight etc.) receives a pretty empty and useless environment, since standard Unix ways of setting variables via e.g. ~/.profile do not work.

http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x

In any case you cannot assume that npm will be installed on user machine.

@develar
Copy link
Member

develar commented Nov 5, 2016

e.g. nodejs/installer#18

@yopbeast
Copy link
Author

yopbeast commented Nov 5, 2016

@develar Hi, sorry i do not assume that it is installed because it's required that node is already installed on the OS to use the app.

The problem is that I did not understand whether it is possible or not execute this command because the response to the issue that you linked does not provide anything from what I read, am i mistaking?

Also I do not understand what is written on StackOverflow, they are talking about to edit a conf file on the OS, i can't ask final app user to edit the file...

What you suggest sorry?

@develar
Copy link
Member

develar commented Nov 5, 2016

What you suggest sorry?

"reconstructing the entire shell environment" nodejs/installer#18 (comment)

@yopbeast
Copy link
Author

yopbeast commented Nov 5, 2016

it's not possible due to node installer?

@yopbeast
Copy link
Author

yopbeast commented Nov 5, 2016

Actually i found that using this:

process.env.PATH = process.env.PATH + ':/usr/local/bin';

exec works, could be a fix or it's going to take me to the hell too? 🗡

@develar
Copy link
Member

develar commented Nov 5, 2016

could be a fix

Yes. But please note — custom user env will be still not supported. So, "reconstructing the entire shell environment" is the only real complete solution.

@yopbeast
Copy link
Author

yopbeast commented Nov 5, 2016

@develar sorry not supported where? on electron?

@develar
Copy link
Member

develar commented Nov 5, 2016

Not supported by your app. For example, if on my machine npm will be installed to another dir. And dir will be specified in the shell PATH.

@yopbeast
Copy link
Author

yopbeast commented Nov 5, 2016

@develar got it thanks :) do you think it's better to always ask which node or which npm and use the path to the executable anyway to have larger support?

@develar
Copy link
Member

develar commented Nov 6, 2016

No, I suggest #880 (comment)

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

No branches or pull requests

2 participants