A short list of hurdles to get Electron working more like Node, and how I'm tackling them.
- using renderer
process.stdin
with Buffer seems difficult/impossible- alternative: send buffered stdin as a string to the renderer
- renderer
process.argv
needs to berequire('remote').process.argv
- should be patched in preload script to ensure your Node dependencies work correctly
- syntax errors in
<script src="index.js">
do not print to terminalwindow.onerror
in a preload script can be used to detect these problems- only provides file, line number and a minimal error message
- stderr gets cluttered with Chromium logs
- can use strip-chromium-logs to fix
- console log / error does not write to stdout / stderr
- can use console-redirect or
require('console')
in preload script to fix
- can use console-redirect or
- requiring a module in
node_modules
will not work as expected from a different directory- see electron/electron#1971
- solution here
- does not fix relative requires: electron/electron#2414
- only supports one preload script
- you may need to pollute global scope to work around this electron/electron#2406
__dirname
and__filename
sometimes don't work, eg if you are serving JS content from a local host- not sure how to tackle this one
- uncaught exceptions show an alert box
- need to tap into process.on('uncaughtException')
- exception may occur before or after app/BrowserWindow is ready
- some modules are optimized for the browser with package.json
"browser"
field- no easy way of handling this in Electron, without using browserify
- builtins like
app
andbrowser-window
do not resolve as they would in a real Node app - development experience can do with some love: still need to set up your own live reloading / file watching
What about something like browserify, electronify?