I'm working on an electron app and within the app, I execute shell mands using child_process.exec
. One of the mands I run is npm run start
; this works perfectly in a dev environment but when I build the application for production all npm
mands fail with showing the following error:
Error: Command failed: npm run start
/bin/sh: npm: mand not found
at ChildProcess.exithandler (child_process.js:287)
at emitTwo (events.js:126)
at ChildProcess.emit (events.js:214)
at maybeClose (internal/child_process.js:925)
at Socket.stream.socket.on (internal/child_process.js:346)
at emitOne (events.js:116)
at Socket.emit (events.js:211)
at Pipe._handle.close [as _onclose] (net.js:554)
I tried running the application in debug mode by running the following mand open MyApp.app/Contents/MacOS/MyApp
and the npm
mands run successfully with no errors.
What could be the issue?
I'm working on an electron app and within the app, I execute shell mands using child_process.exec
. One of the mands I run is npm run start
; this works perfectly in a dev environment but when I build the application for production all npm
mands fail with showing the following error:
Error: Command failed: npm run start
/bin/sh: npm: mand not found
at ChildProcess.exithandler (child_process.js:287)
at emitTwo (events.js:126)
at ChildProcess.emit (events.js:214)
at maybeClose (internal/child_process.js:925)
at Socket.stream.socket.on (internal/child_process.js:346)
at emitOne (events.js:116)
at Socket.emit (events.js:211)
at Pipe._handle.close [as _onclose] (net.js:554)
I tried running the application in debug mode by running the following mand open MyApp.app/Contents/MacOS/MyApp
and the npm
mands run successfully with no errors.
What could be the issue?
Share Improve this question asked Mar 29, 2019 at 9:08 HackAfroHackAfro 7201 gold badge13 silver badges28 bronze badges 5- Is node installed on the non dev machine ? – Seblor Commented Mar 29, 2019 at 9:10
- I'm running the prod version of the application on my machine which has nide installed – HackAfro Commented Mar 29, 2019 at 9:12
- This issue might be related : github./electron/electron/issues/7688 – Seblor Commented Mar 29, 2019 at 9:14
- 1 Thanks @Seblor this solved my problem. – HackAfro Commented Mar 29, 2019 at 9:39
- 2 You should create an answer with the plete steps you took to solve your issue, since I only directed you to some github issue. It might be helpful for other people getting the same error. – Seblor Commented Mar 29, 2019 at 9:40
1 Answer
Reset to default 10The issue that the environment variable of $PATH is wrong inside the packaged app, it works in development because the application is launched from the terminal which gives it access to the $BASH profile.
To solve this problem I used this package fix-path. I installed the package and added the following snippet at the top of the file
if (process.env.NODE_ENV === 'production') {
const fixPath = require('fix-path');
fixPath();
}
I came to this answer after going through this issue on GitHub. Thanks to @Seblor