45

After installing a native module via npm for use with Electron (atom shell) I'm trying to run electron-rebuild:

>>./node_modules/.bin/electron-rebuild

from the project directory,b "~/project_js/React-Redux-Py-Electron/" (which contains node_modules/). But I receive this error message:

>>Unable to find Electron app at ~/project_js/React-Redux-Py-Electron/console.log(process.versions.modules)

Using versions:

node v6.2.0, 
npm 3.8.9, 
electron-prebuilt 1.2.0, 
electron-rebuild 1.1.4, 

which I believe are all the latest. At one time, perhaps before some version upgrades, this worked.

Can anyone explain and suggest a fix? Thanks.

Auguste
  • 2,007
  • 2
  • 17
  • 25
SteveB
  • 851
  • 2
  • 7
  • 15
  • Did you ever solve this? I'm getting the same error but from https://github.com/chentsulin/electron-react-boilerplate . Thanks. – elimisteve Jul 01 '16 at 04:42
  • 1
    No I didn't. I ended up using the less convenient rebuild method. As much as I like Electron, stuff like this makes me think it's still a bit "rough around the edges". – SteveB Jul 02 '16 at 11:29
  • 1
    `npm run build && npm start` fixed it for me – Trey Huffine Aug 10 '16 at 14:23

6 Answers6

95

Check if your package.json has "main" key. Here main.js is your Electron Configuration JS file.

{
  "name": "appname",
  "version": "0.0.0",
  "license": "MIT",
  "main": "main.js"
}
Abraham Jagadeesh
  • 1,757
  • 1
  • 23
  • 21
14

The entry point file name and package.json main file name should be same. Consider your entry point file name is app.js then package.json looks like

{
  "name": "myelectron",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "electron ."
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "electron": "^2.0.3"
  }
}
Mr. Ratnadeep
  • 591
  • 4
  • 10
9

For me it was throwing this error because of missing package.json file in the folder I was running electron command. Make sure the folder consists of files named

  1. main.js
  2. index.html
  3. package.json

and define variables electron, app and BrowserWindow in main.js are as

               const electron = require('electron');             
               const {app, BrowserWindow} = electron;  
Penkey Suresh
  • 5,816
  • 3
  • 36
  • 55
6

Make sure you defined entry point for the application. generally, it's always a index.js or main.js. You need to specify in package.json as an entry point of application. In this case what happened is, electron need the entry point and it didn't find from package.json and unable to start the main process. To fix it up, You can add main property as root property in package.json as given below,

{
  "name": "YOUR_APP_NAME",
  "version": "1.0.0",
  "main": "main.js"
}

Another important thing is, just check once the dependencies by running command npm list --depth=0 and confirm that electron is there.

Kiran Maniya
  • 8,453
  • 9
  • 58
  • 81
5

for me the issue was caused due to inconsistency with the name when running the Electron command.

Ensure that the filename provided for run should be the same as the one provided in the main entry in package.json e.g. on Mac OS /Applications/Electron.app/Contents/MacOS/Electron hello-world matches with the hello-world.js in main package.json

{
  "name": "first_electron_app",
  "version": "0.0.1",
  "main": "hello-world.js",
  "dependencies": {    
  }
}
Angus
  • 70
  • 6
pg2286
  • 1,011
  • 12
  • 21
1

npm run build && npm start fixed it for me

Trey Huffine
  • 242
  • 3
  • 9