2

I have created an angular 10 project using the angular-CLI. Following that that I have installed Electron and done this: changed src/index.html base to Installed Electron locally. but when run my code, it shows have some error.

how can I fix this error?

this is my main.js file

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

let win;

function createWindow () {
  // Create the browser window.
  win = new BrowserWindow({
    width: 600, 
    height: 670,
    icon: `file://${__dirname}/dist/assets/logo.png`
  })

  win.loadURL(`file://${__dirname}/dist/index.html`)

  // uncomment below to open the DevTools.
  // win.webContents.openDevTools()

  // Event when the window is closed.
  win.on('closed', function () {
    win = null
  })
}

// Create window on electron intialization
app.on('ready', createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', function () {

  // On macOS specific close process
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', function () {
  // macOS specific close process
  if (win === null) {
    createWindow()
  }
})

this is my package.json file

{
  "name": "angu",
  "version": "0.0.0",
  "main": "main.js",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "electron":"electron .",
    "electron-build": "ng build --prod && npm run electron ."
  },

this is my index.html file

  <base href="./">

error

Tharindu Lakshan
  • 3,995
  • 6
  • 24
  • 44

1 Answers1

2

I were also stuck in this problem for last 2 days. And after a lot of searching and getting understanding of electron. I fixed this issue and issues after that issue.

For fixing the issue of Please verify that the package.json has a valid "main" entery

You need to update your main in package.json file with path of main.js file. Most probably that will be

"main": "src/main.js",

When you will do this change, run the command npm run electron-build. It will create the build of your electron app but will not show anything on the page and if you see the console, here you will see the 1 error Not allowed to load local resource: . To solve this error you shoudl visit these following links

Electron - Not allowed to load local resource

https://github.com/JacopoMangiavacchi/TFRecords/issues/1

Yisal Khan
  • 359
  • 3
  • 10