Problem with Ubuntu 18.04 and Electron


#1

Hello everyone, I am new for here.

I want know why does it happen if I read correct with Write first app

json generated from npm init = ok

main.js looks like this
const electron = require(‘electron’)

const {app, BrowserWindow} = require('electron')
  
  function createWindow () {
    // Create the browser window.
    win = new BrowserWindow({width: 800, height: 600})
  
    // and load the index.html of the app.
    win.loadFile('index.html')
  }
  
  app.on('ready', createWindow)

const {app, BrowserWindow} = require('electron')
  
  // Keep a global reference of the window object, if you don't, the window will
  // be closed automatically when the JavaScript object is garbage collected.
  let win
  
  function createWindow () {
    // Create the browser window.
    win = new BrowserWindow({width: 800, height: 600})
  
    // and load the index.html of the app.
    win.loadFile('index.html')
  
    // Open the DevTools.
    win.webContents.openDevTools()
  
    // Emitted when the window is closed.
    win.on('closed', () => {
      // Dereference the window object, usually you would store windows
      // in an array if your app supports multi windows, this is the time
      // when you should delete the corresponding element.
      win = null
    })
  }
  
  // This method will be called when Electron has finished
  // initialization and is ready to create browser windows.
  // Some APIs can only be used after this event occurs.
  app.on('ready', createWindow)
  
  // Quit when all windows are closed.
  app.on('window-all-closed', () => {
    // On macOS it is common for applications and their menu bar
    // to stay active until the user quits explicitly with Cmd + Q
    if (process.platform !== 'darwin') {
      app.quit()
    }
  })

app.on(‘activate’, () => {
// On macOS it’s common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow()
}
})

index.html likes this




Hello World!


Hello World!


We are using node ,
Chrome ,
and Electron .

Result:
npm start:
> your-app@1.0.0 start /home/sourceskyboxer/your-app
> electron .

(electron:27330): Gdk-WARNING **: 23:12:59.524: The GDK_NATIVE_WINDOWS environment variable is not supported in GTK3.
See the documentation for gdk_window_ensure_native() on how to get native windows.
App threw an error during load
/home/sourceskyboxer/your-app/main.js:15
const {app, BrowserWindow} = require('electron')
       ^

SyntaxError: Identifier 'app' has already been declared
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:606:28)
    at Object.Module._extensions..js (module.js:653:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:504:12)
    at Function.Module._load (module.js:496:3)
    at loadApplicationPackage (/home/sourceskyboxer/your-app/node_modules/electron/dist/resources/default_app.asar/main.js:287:12)
    at Object.<anonymous> (/home/sourceskyboxer/your-app/node_modules/electron/dist/resources/default_app.asar/main.js:328:5)
    at Object.<anonymous> (/home/sourceskyboxer/your-app/node_modules/electron/dist/resources/default_app.asar/main.js:365:3)
A JavaScript error occurred in the main process
Uncaught Exception:
/home/sourceskyboxer/your-app/main.js:15
const {app, BrowserWindow} = require('electron')
       ^

SyntaxError: Identifier 'app' has already been declared
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:606:28)
    at Object.Module._extensions..js (module.js:653:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:504:12)
    at Function.Module._load (module.js:496:3)
    at loadApplicationPackage (/home/sourceskyboxer/your-app/node_modules/electron/dist/resources/default_app.asar/main.js:287:12)
    at Object.<anonymous> (/home/sourceskyboxer/your-app/node_modules/electron/dist/resources/default_app.asar/main.js:328:5)
    at Object.<anonymous> (/home/sourceskyboxer/your-app/node_modules/electron/dist/resources/default_app.asar/main.js:365:3)

That is not working now. Why do I should understand. I thought you have to improve documentations.