4

I'm new to electron and have made my first electron application, it runs normally running npm start but when using npm run I am unable to execute my application. (I am running ubuntu linux) The cli gives this error message when running the executable file:

A JavaScript error occurred in the main process
Uncaught Exception:
Error: Cannot find module '/home/user/Documents/dev/cocoa/cocoa-linux-x64/resources/app/index.js'
    at Module._resolveFilename (module.js:455:15)
    at Function.Module._resolveFilename (/home/user/Documents/dev/cocoa/cocoa-linux-x64/resources/electron.asar/common/reset-search-paths.js:35:12)
    at Function.Module._load (module.js:403:25)
    at Object.<anonymous> (/home/user/Documents/dev/cocoa/cocoa-linux-x64/resources/electron.asar/browser/init.js:171:8)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.runMain (module.js:590:10)

This is my package.json :

{
  "name": "cocoa",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "electron main.js",
    "package-linux" : "electron-packager . --platform=linux --arch=x64 --electron-version=1.4.13"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "electron-packager": "^8.7.1"
  }
}

this is the main.js file :

const electron = require('electron')
const {app, BrowserWindow} = electron

app.on('ready', ()=> {
  let win = new BrowserWindow({
    width:400,
    height:400
  })
  win.loadURL('http://google.com')
})

Does anyone know what I am doing wrong, thank you for your help.

1 Answer 1

5

Ok, that was really stupid. I had named the main js file for the project main.js when in actual fact it had to be named index.js problem solved!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.