While attempting to use electron to write a cross-platform utility, I ran into an unexpected problem: The application would error out with a few weird messages like these:
- App threw an error during load
Error: Cannot find module 'app'
at Module._resolveFilename (module.js:455:15)
- App threw an error when running [TypeError: Cannot read property 'on' of undefined]
TypeError: Cannot read property 'on' of undefined
- require(“electron”).app is undefined. I npm installed fresh modules. Unsure what to do [stackoverflow.com]
- Cannot find module app when trying to run electron app [stackoverflow.com]
- TypeError: Cannot read property 'on' of undefined [github.com/electron]
- #112: Error occurred when running `electron .` [github.com/platformio]
The frustrating thing about this problem is how simple it is to solve: I wasted 3 hours trying to figure out what was going wrong with my setup. It wasn't until I stumbled across zyeek's Stack Overflow answer that I was able to move on.
What was the solution? In my case it involves not using a terminal plugin for Atom (specifically: platformio-ide-terminal). Once I ran 'npm start' from a system terminal (I'm running Lubuntu 16.04) the problem went away. There is an open issue on the atom terminal github from November 2016 that describes the issue.