Tag Archives: electron

[Solved] electron-vue project error: Object.fromEntries is not a function electron-vue

electron-vue scaffold project build error: Object.fromEntries is not a function

Project directory

Front console print error:

Solution: install polyfill-object.fromentries and execute the command in the project root directory

npm i polyfill-object.fromentries

And then

import

import 'polyfill-object.fromentries';

[Solved] electron Package and Startup Error: Error: ENOENT: no such file or directory, open ‘xxx/manifest.json‘‘

Start the error report after packaging with electron-builder:

Reading /xxx/manifest.json failed.
Error: ENOENT: no such file or directory, open '/xxx/manifest.json'
    at Object.fs.openSync (fs.js:558:18)
    at Object.module.(anonymous function) [as openSync] (ELECTRON_ASAR.js:173:20)
    at Object.fs.readFileSync (fs.js:468:33)
    at Object.fs.readFileSync (ELECTRON_ASAR.js:506:29)
    at getManifestFromPath (/xxx/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/browser/chrome-extension.js:34:26)
    at Function.BrowserWindow.addDevToolsExtension (/xxx/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/browser/chrome-extension.js:373:22)
    at App.Z.enabled.X.on (/xxx/webpack:/~/electron-debug/index.js:78:1)
    at emitTwo (events.js:111:20)
    at App.emit (events.js:191:7)

Solution:

1. Execute the following command:

npm install vue-devtools --global

2. Modify src/main/index.dev.js as follows:

import {  BrowserWindow } from 'electron'; //Add
/* eslint-disable */

// Install `electron-debug` with `devtron`
// require('electron-debug')({ showDevTools: true })
require('electron-debug')() //Modify

// Install `vue-devtools`
require('electron').app.on('ready', () => {
  let installExtension = require('electron-devtools-installer')
  //Comment out
  // installExtension.default(installExtension.VUEJS_DEVTOOLS)
  //   .then(() => {})
  //   .catch(err => {
  //     console.log('Unable to install `vue-devtools`: \n', err)
  //   })
  //Add
  BrowserWindow.addDevToolsExtension('node_modules/vue-devtools/vender')
})
// Require `main` process to boot app
require('./index')

3. Recompile:

npm run build:win32

4. Repackage:

electron-builder

It can start normally:

[Solved] Uncaught Error: @electron/remote is disabled for this WebContents

There is an error using the remote module:

Uncaught Error: @electron/remote is disabled for this WebContents. Call require("@electron/remote/main").enable(webContents) to enable it.
    at IpcMainImpl.<anonymous>

 

according to the prompt, you need to add a line: require(“@electron/remote/main”).enable(webContents) in main.js, but if it is added directly, the webcontents is not defined error will be displayed.

You can’t add it directly, webContents should be preceded by the defined variable name, as follows, webContents should be replaced with mainWindow.webContents.

[Solved] electron Error: Uncaught TypeError: Cannot read property ‘BrowserWindow‘ of undefined

Electronic version 16+

There is a problem when using the remote module. The code is as follows:

const BrowserWindow = require(‘electron’). remote. BrowserWindow;

report errors:

Uncaught TypeError: Cannot read property ‘BrowserWindow’ of undefined

Solution:

1. Install remote:

npm install –save @electron/remote

2. demo2.js:

3. main.js:

It’s ready to run. The version of electron is updated too fast, and the rules are changed too fast.

[Solved] electron-builder Package mac Error: panic: runtime error: index out of range

An error is reported in the packaging mac of electron builder. The detailed error information is as follows:

goroutine 1 [running]:
github.com/develar/app-builder/pkg/icons.ConvertIcnsToPng(0xc0000ca630, 0x2d, 0x7ffd9f40874a, 0x2e, 0x2, 0x2, 0xc0000ca630, 0x2d, 0xe53320)
	/Volumes/data/Documents/app-builder/pkg/icons/icns-to-png.go:60 +0x4ab
github.com/develar/app-builder/pkg/icons.doConvertIcon(0xc00012a400, 0x5, 0x8, 0xc00025ec20, 0x2, 0x2, 0x7ffd9f4086ec, 0x3, 0x7ffd9f40874a, 0x2e, ...)
	/Volumes/data/Documents/app-builder/pkg/icons/icon-converter.go:226 +0xa0d
github.com/develar/app-builder/pkg/icons.ConvertIcon(0xc0000ad3c0, 0x97, 0x0, 0xf6400f7800000000)
	/Volumes/data/Documents/app-builder/pkg/icons/icon-converter.go:56 +0xd6
github.com/develar/app-builder/pkg/icons.ConfigureCommand.func1(0xc0002375f0, 0x40b705, 0xc2b0e0)
	/Volumes/data/Documents/app-builder/pkg/icons/icon-converter.go:33 +0x7f
github.com/alecthomas/kingpin.(*actionMixin).applyActions(0xc000124d98, 0xc0002375f0, 0x0, 0x0)
	/Volumes/data/go/pkg/mod/github.com/alecthomas/[email protected]+incompatible/actions.go:28 +0x6d
github.com/alecthomas/kingpin.(*Application).applyActions(0xc0000e8780, 0xc0002375f0, 0x0, 0x0)
	/Volumes/data/go/pkg/mod/github.com/alecthomas/[email protected]+incompatible/app.go:557 +0xdc
github.com/alecthomas/kingpin.(*Application).execute(0xc0000e8780, 0xc0002375f0, 0xc00021b150, 0x1, 0x1, 0x0, 0x0, 0x0, 0x904545)
	/Volumes/data/go/pkg/mod/github.com/alecthomas/[email protected]+incompatible/app.go:390 +0x90
github.com/alecthomas/kingpin.(*Application).Parse(0xc0000e8780, 0xc0000ae010, 0xf, 0xf, 0xc0000e8780, 0xc00008a058, 0x0, 0x0)
	/Volumes/data/go/pkg/mod/github.com/alecthomas/[email protected]+incompatible/app.go:222 +0x213

Solution:
put 512×512 in the icons directory of the icon Png icon to complete packaging
for example:
dist/icons/512x512.png

[Solved] electron Use remote Error: Cannot read properties of undefined (reading ‘BrowserWindow‘)

Recently, I wrote a small demo of remote while learning electron. There is such a code:

const BrowserWindow = require("electron").remote.BrowserWindow;

An error will be reported, as shown in the following figure:

Then I went to the Internet and looked at some articles. It seems to be a problem with the version. My electron is @V16.0.4, and remote abandoned the remote module in electron12, so we need to install the remote package ourselves.

1. First install the @electron/remote package under the project root directory:

npm install @electron/remote --save

2. Initialize in the main process:

require("@electron/remote/main").initialize();
require("@electron/remote/main").enable(mainWindow.webContents);

3. And set enableremotemodule and contextisolation in the main process webpreferences:

 webPreferences: {
    nodeIntegration: true,
    contextIsolation: false,
    enableRemoteModule: true, // use remote module
 },

4. Set in the rendering process

const BrowserWindow = require("@electron/remote").BrowserWindow;

Well, this is my overall Code:

Main process

var electron = require("electron");
var app = electron.app; // Reference app
var BrowserWindow = electron.
var mainWindow = null; // Specify the main window to open

// When electron has finished initializing and is ready to create a browser window
// This method is called
app.on("ready", () => {
  mainWindow = new BrowserWindow({
    width: 800,
    height: 800,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false,
      enableRemoteModule: true, // use remote module
    },
  });

  require("@electron/remote/main").initialize(); // initialize
  require("@electron/remote/main").enable(mainWindow.webContents);
  mainWindow.loadFile("demo2.html"); // load the index.html page
  mainWindow.openDevTools(); // open developer tools

  mainWindow.on("closed", () => {
    mainWindow = null;
  });
});

Subprocess

const btn = this.document.querySelector("#btn");
const BrowserWindow = require("@electron/remote").BrowserWindow;

window.onload = () => {
  btn.onclick = () => {
    newWin = new BrowserWindow({
      width: 500,
      height: 500,
    });

    newWin.loadFile("load.html");
    newWin.on("closed", () => {
      newWin = null;
    });
  };
};

Result display

[Solved] electron project Package Error: spawn exe\dll ENOENT

Error after electron packaging: spawn exe enoent error solution.

Today, an error occurred when the project was running after packaging: spawn exe enoent error. When looking for a solution, I thought it should be that the referenced exe program was packaged into the app It is caused by the ASAR file, so the EXE file is not packaged into the app ASAR files should solve the problem.

I packed it with electron builder in Vue config.JS file, in Vue config.JS add the following code

pluginOptions: {
		electronBuilder: {
			builderOptions: {
				asar: true,
				asarUnpack: ['exeFiles'],//The folder where the referenced dll/exe files are stored
				extraFiles: {
					from: 'exeFiles',// the folder where the referenced dll/exe files are stored, my project is in the same directory as vue.config.js
					to: '. /exeFiles'//the location of the folder after packaging, I packaged this way before and after the reference relationship does not change, spawn code will not have to change
				},		
		}
	}

If you use the older version of Vue cli, it should be in package JSON, the principle is similar.

How to Solve electron import page Error

Uncaught ReferenceError: require is not defined
at index. js:1

index. Index. HTML file js

The following is index.js file

index.JS error

You need to add the following code in the created window: see the first figure for details

 webPreferences: {
    webSecurity: false, // Cancel cross-domain
    nodeIntegration: true, // v5 version requires this line
    contextIsolation: false, // v12 version needs to add this line
    enableRemoteModule:true // v10 version Turn on remote module
}

How to Solve MAC electronic installation dependent startup error

file: https://github.com/electron/electron/issues/8466

Error message:

Solution:

Switch to node_ The index file used for the electron pair in modules, then enter the terminal and execute it in the current directory with node install.js before completing the electron dependent installation

Then go to the project again and start the project

An error is reported when the electron Vue Vue component introduces the electron

Question:

Remote module of electron introduced into Vue component:

let { remote } = require("electron");

An error is reported when the electron application starts.

solve:

1. Add window before require, that is:

let { remote } = window.require("electron");

2. Add vue.config.js file in the root directory of the project, and the configuration is as follows:

module.exports = {
    pluginOptions: {
        electronBuilder: {
            nodeIntegration: true
        }
    }
}

The above two methods can be solved.

Of course, the webpreferences property of browserwindow should also be configured correctly:

webPreferences: {
      nodeIntegration: true,
      contextIsolation: false,
      enableRemoteModule: true
    }