electron: Can't run command line tool using child_process after packaged
- Electron version: 1.4.4
- Operating system: OSX 10.11.6
The user scenario is like this:
- user selects a directory
- use node’s child_process to run
npm installunder this directory
The code snippets related to running command line is: (ES6)
import cp from 'child_process';
import { ipcRenderer } from 'electron';
export function runCommand(command, option, done) {
const child = cp.exec(command, option);
ipcRenderer.sendSync('newChildProcess', child.pid);
done({
type: 'id',
data: child.pid
});
child.stdout.on('data', (data) => {
done({
type: 'stdout',
data
});
});
child.stderr.on('data', (data) => {
done({
type: 'stdout',
data
});
});
child.on('close', (code) => {
done({
type: 'close',
data: code
});
});
}
In development phase, it works well. But after I package the code as dmg on Mac, the exec throw a “/bin/sh: npm command not found” error with an exit code 127. I’m sure I have installed npm on my machine.
Is there anyone know how to fix this?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 6
- Comments: 15 (2 by maintainers)
Commits related to this issue
- fix 'command not found' on macos when deploy with shell. see: https://github.com/electron/electron/issues/7688 https://github.com/gaoyoubo/hexo-client/pull/59 — committed to gaoyoubo/hexo-client by gaoyoubo 5 years ago
- fix path on macos in built app https://github.com/electron/electron/issues/7688 — committed to lecstor/dev-stack-dashboard by lecstor 4 years ago
You might want to take a look at using something like https://github.com/sindresorhus/fix-path
Closing this out.
I found a note on official document, is that the reason?
Does that means if I packaged the app as
asar, I can’t usechild_process.execto execute command line tool in my app?npm install -save fix-path It works fine when I run electron . from my-app. However, once packaged I see “Error: Cannot find module” how do it ??