我在使用最新版本的 Electron 时遇到此错误。我在主 javascript 文件中将 nodeIntegration 设置为 true 。我已从工作的 Electron 应用程序复制并粘贴了此代码,但它似乎不适用于我的新应用程序。
电子版本:^12.0.0
我的主要JS
//Require Electron
const { BrowserWindow, app, autoUpdater, globalShortcut, ipcMain } = require('electron');
const main = require('electron-reload');
//Electron reload
const electron_reload = require('electron-reload')(__dirname);
//Disable security warnings
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
//Main window
function createMain() {
const main = new BrowserWindow({
minWidth: 425,
minHeight: 524,
width: 1600,
height: 900,
frame: null,
icon: './assets/icon.png',
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true,
nodeIntegrationInSubFrames: true,
enableRemoteModule: true,
}
});
main.loadFile('./HTML/index.html');
main.setMenu(null);
main.webContents.toggleDevTools();
main.webContents.on('did-finish-load', function () {
main.show();
//Ctrl+Shift+I - Open Developer Tools
globalShortcut.register('CommandOrControl+Shift+I', () => {
console.log('Developer Tools Opened');
main.webContents.toggleDevTools();
});
//Make full screen
globalShortcut.register('F11', () => {
main.maximize();
})
});
//Tries to quit the application when main window is closed
main.on('closed', function () {
app.quit();
});
}
//Once the Electron application is initialised (when it is ready) the function createMain is called
app.whenReady()
.then(createMain)
.then(console.log('Launching ChecklistsPro'));
//When the application is launched, if it has no windows open then it will call the createMain function
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createMain();
}
});
Run Code Online (Sandbox Code Playgroud)
尝试使用要求
const electron = require('electron');
Run Code Online (Sandbox Code Playgroud)
我也有同样的问题。它附带从 Electron 11.x 到 12.x 的更新,请参见此处:https ://www. Electronjs.org/releases/stable#release-notes-for-v1200
您必须禁用上下文隔离,在新的电子版本中默认情况下该设置已更改为 true。
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
})
win.loadFile('index.html')
}
Run Code Online (Sandbox Code Playgroud)
另一个解决方案是降级到 Electron 11.x,其中 contextIsolation: false 是默认值。
我的来源: https ://www.reddit.com/r/ Electronjs/comments/lxjva0/required_not_define_but_nodeintegration_set_to/ 电子变更日志图片
| 归档时间: |
|
| 查看次数: |
1964 次 |
| 最近记录: |